2
$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コードを見つけて動作しましたが、表示時にユーザー名の前にマシン名を表示したいと思います。どうすればそれを行うことができますか?

以下のようなので -

マシン名: ユーザー名

私はパワーシェルの初心者です...どんな助けもいただければ幸いです! ありがとう!:)

4

2 に答える 2

4

これを試して

$MachineList = Get-Content -Path c:\ListOfMachines.txt; # One system name per line
foreach ($Machine in $MachineList){
    ($Machine + ": " + @(Get-WmiObject -ComputerName $Machine -Namespace root\cimv2 -Class Win32_ComputerSystem)[0].UserName);
}
于 2013-11-14T16:36:53.233 に答える
1

これを試して:

Get-Content -Path c:\ListOfMachines.txt | % {
  Get-WmiObject -ComputerName $_ -Namespace root\cimv2 -Class Win32_ComputerSystem -erroraction silentlycontinue | % {
    "$($_.Name): $($_.username)"
  }
}
于 2013-11-14T16:41:19.520 に答える