$Excel = New-Object -ComObject Excel.Application $Excel.Visible = $True $Workbook = $Excel.Workbooks.Open("C:\Pfad\zur\Excel-Datei.xlsx") $Worksheet = $Workbook.Worksheets.Item(1) $Range = $Worksheet.Range("A1:A10") foreach ($cell in $Range.Cells) { $user = "net user /domain " + $cell.Value.ToString() $resultFile = "C:\Temp\result.txt" $cmd = "$user > $resultFile" Invoke-Expression $cmd $result = Get-Content $resultFile $fullName = $result -match "Full Name\s+([\w\s]+)" | Out-Null ; $Matches[1] if ($fullName) { $cell.Offset(0, 1).Value = $fullName } else { $cell.Offset(0, 1).Value = "Full Name not found" } Remove-Item $resultFile } $Workbook.Save() $Workbook.Close() $Excel.Quit()