Hi ,
I need some help on copying the script to remote servers and then execute the same copying script.
I know how to copy files from source to destination, but not able to execute the file script . please help me.
Below is the script.
$computers = get-content "C:\psscripts\servers.txt"
$source = "C:\test\script.ps1"
$destination = "C$\temp\"
foreach ($computer in $computers) {
if ((Test-Path -Path \\$computer\$destination))
{Copy-item $source -Destination "\\$computer\$destination" -Recurse}
else
{
"\\$computer\$destination is not reachable or does not exist"
}
}
powershell script for copy script to remote servers and then execute the script
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: powershell script for copy script to remote servers and then execute the script
You don't have to copy the script. Just execute it remotely.
Invoke-Command -File C:\test\script.ps1 -Computer $computer
Invoke-Command -File C:\test\script.ps1 -Computer $computer