Translate

Powershell script to copy one file to multiple servers or systems


Powershell script to copy one file to multiple servers or systems

import-module activedirectory;


$adservers = get-adcomputer -filter {operatingsystem -like "*Windows Server 2008 R2 Standard*"} -SearchBase “ou=computers,ou=name,dc=domain,dc=com”;

$destination = "c$";
$source = "\\server name\C$\grouplist.txt";

foreach ($adserver in $adservers) {


    $servername = $adserver.name;



foreach ($computer in $servername) {

if ((Test-Path -Path \\$computer\$destination))
{

Copy-Item $source -Destination \\$computer\$destination -Verbose
}

else {

"\\$computer\$destination is not reachable or does not exist"
}
}write-host $servername;
$computer >> c:\sname.csv
}


No comments:

Post a Comment

Quotes About Love