1

出力ファイルで $_ を適切に使用するにはどうすればよいですか? これが私のコードです:

get-content computers.txt | 
  Where {$_ -AND (Test-Connection $_ -Quiet)} |
    foreach { Get-Hotfix -computername $_ } | 
      Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
        convertto-csv | out-file "C:\$_.csv"

テキスト ファイルにリストされているすべてのコンピューターに対して get-hotfix を実行しようとしています。そのコンピューター名をファイル名として CSV にエクスポートします。

4

3 に答える 3

1

computer.txtファイルを処理するために1つのパイプラインが必要であり、foreach各コンピューターの修正プログラムのリストを処理するために内部にネストされたパイプラインが必要です。

get-content .\computers.txt |
  Where {$_ -AND (Test-Connection $_ -Quiet)} |
    foreach { 
      Get-Hotfix -computername $_ |
        Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
          convertto-csv | out-file "C:\$_.csv" 
    }

編集: PowerShellのローカルパスに必要なため、に変更computers.txtされました.\computers.txt

于 2012-08-23T01:15:10.790 に答える