私はPowershellを初めて使用しますが、最善を尽くしました。アレイ内のすべての XP マシンのすべてのユーザーのデスクトップにファイルをコピーするスクリプトを作成しようとしています。スクリプトは基本的に、「マシンが ping 可能な場合はファイルをコピーし、そうでない場合はコピーしないでください」と述べています。次に、この情報を CSV ファイルにエクスポートして、さらに分析したいと考えています。
すべてを設定しましたが、何をしても、最後に実行した PC のみがエクスポートされます。すべての PC で実行されているようですが (txt ファイルへの出力でテスト済み)、すべてのマシンを CSV に記録するわけではありません。誰でもアドバイスできますか?
$ArrComputers = "PC1", "PC2", "PC3"
foreach ($Computer in $ArrComputers) {
$Reachable = Test-Connection -Cn $Computer -BufferSize 16 -Count 1 -ea 0 -quiet
$Output = @()
#Is the machine reachable?
if($Reachable)
{
#If Yes, copy file
Copy-Item -Path "\\servername\filelocation" -Destination "\\$Computer\c$\Documents and Settings\All Users\Desktop\filename"
$details = "Copied"
}
else
{
#If not, don't copy the file
$details = "Not Copied"
}
#Store the information from this run into the array
$Output =New-Object -TypeName PSObject -Property @{
SystemName = $Computer
Reachable = $reachable
Result = $details
} | Select-Object SystemName,Reachable,Result
}
#Output the array to the CSV File
$Output | Export-Csv C:\GPoutput.csv
Write-output "Script has finished. Please check output files."