Trying to improve my PowerShell abilities. Sorry for the noob script. I am working on a loop that will perform the following against a list of servers:
- Removes old folder
- Creates new directory
- Copy a directory from one host to others on the serverlist
- Remove old folderB
- Rename the files in the copied directory
I know this is probably inefficient and may be the wrong loop. When ran, the commands all work successfully BUT it does not move on to the other servers in the list. I imagine I am doing something wrong, any ideas?
$strComputers = get-content c:\temp\serverlist3.txt
$source = "\\server\OS\Temp\WSUS\"
$destination = "\\$strComputer\OS\temp\wsus"
$renamea = "\\$strComputer\OS\TEMP\WSUS\clientwsusInstall-win2008-new.cmd"
$renameb = "\\$strComputer\OS\TEMP\WSUS\clientwsusInstall-win2003-new.cmd"
$destinationc = "\\$strComputer\OS\temp\Wsus-new"
# Run through the Array of Computers
##remove old wsus dir
foreach ($strComputer in $strComputers) {
rm -r $destination
new-item -type directory -path $destination
robocopy $source $destination
rm -r $destinationc
rni -path $renamea clientwsusInstall-win2008.cmd
rni -path $renameb clientwsusInstall-win2003.cmd
}
Thanks for you input!!