Trying to get these two to work but keep getting errors. Basically looking to pickup all files from C:\Temp\Test with .txt extension and copy it to Server1 and Server2 D:\Temp\Test.
Doesn't work...
$servers = "Server1","Server2"
$SourcePath = (Get-ChildItem C:\Temp\Test *.txt).Name
$servers | ForEach {
Invoke-Command $servers -ScriptBlock {
$CompName = (Get-WmiObject -Class Win32_ComputerSystem).Name
$DestPath = "\\$CompName\D$\Temp\Test"
Copy-Item $SourcePath -Destination $DestPath -Recurse
}
}