powershell script for copy script to remote servers and then execute the script
Posted: Tue Jun 26, 2018 3:07 am
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"
}
}
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"
}
}