1
$computers = Get-Content -Path C:\output\output.txt
$output = '\\PCname\c$\output\'
$output1 = '.txt'
($output2 =$output+$computers+$output1)
msinfo32.exe /report $output2 /computer $computer

What I am getting is the msinfo32.exe /report $output2 /computer $computer is reading the first PCname and only that name and writing the file name is each PCname with a space between each of them. Sorry for what most will seem to be a simple question I just started using PS.

Thanks

4

1 回答 1

1

你这里有两个问题。

  1. 要将字符串正确连接到路径中,您需要使用Join-Path
  2. 您只获得第一个计算机名称,因为您没有循环浏览您的计算机列表。

快速而肮脏的修订(假设每台计算机名称都在自己的行中output.txt

$computers = Get-Content -Path C:\output\output.txt;  
$output = '\\PCname\c$\output\';  
$output1 = '.txt';  
$computers | foreach-object {
    $output2 = (join-path -path $output -childpath $_) + ".txt";  
    msinfo32.exe /report $output2 /computer $_;  
}
于 2013-05-14T16:04:54.983 回答