$MachineList = Get-Content -Path "E:\ps\comp list\Test Computers.txt"; # One system name per line
foreach ($Machine in $MachineList)
{
($Machine + ": " + @(Get-WmiObject -ComputerName $Machine -Namespace root\cimv2 -Class Win32_ComputerSystem -erroraction silentlycontinue)[0].UserName);
Write-Output ($Machine + ": " + @(Get-WmiObject -ComputerName $Machine -Namespace root\cimv2 -Class Win32_ComputerSystem -erroraction silentlycontinue)[0].UserName) | Out-File "E:\ps\comp output\Test Computers.txt" -Append
}
更新:これが実際のスクリプトです。ご協力ありがとうございます! :) コンピューターのリストを画面に表示し、それらをファイルに書き込みます。
このpowershellコードを見つけて動作しましたが、表示時にユーザー名の前にマシン名を表示したいと思います。どうすればそれを行うことができますか?
以下のようなので -
マシン名: ユーザー名
私はパワーシェルの初心者です...どんな助けもいただければ幸いです! ありがとう!:)