Advertisement
Guest User

Untitled

a guest
May 13th, 2014
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $directory="201403260208"
  2. $loop=0
  3. $wait=60
  4. $totalfixes=0
  5. $fixes=0
  6.  
  7.  
  8. While($true)
  9. {
  10.     $loopstart = Get-Date
  11.     $fixes = 0
  12.     #IP range for affected workstations (172.16.1.50 - 172.16.1.250)
  13.     for ($i=50; $i -le 250; $i++)
  14.     {
  15.         $computer = "172.16.1.$i"
  16.         if (Test-Connection -Cn $computer -Count 1 -ea 0 -quiet)
  17.         {
  18.         $time = Get-Date -format "HH:mm"
  19.             if ((test-path "\\$computer\c$\Program Files (x86)") -and -not (test-path "\\$computer\c$\Program Files (x86)\Common Files\Government\Program\$directory\"))
  20.             {
  21.                 Write-host "$time Starting fix: $computer"
  22.                 robocopy "C:\fixgovernment\$directory" "\\$computer\c$\Program Files (x86)\Common Files\Government\Program\$directory" /MIR /E /R:0 /W:1 /NJH /NJS /NDL /NC /NS /NP /NFL /A-:SH
  23.                 $result="FIXED"
  24.                 $fixes++
  25.             }
  26.             else
  27.             {
  28.                 #correct directory already exists
  29.                 $result="Skipped"
  30.             }
  31.         }
  32.         else
  33.             {
  34.                 #IP is offline or not a windows machine
  35.                 $result="Offline"
  36.             }
  37.         Write-host "$time $result: $computer"
  38.     }
  39.     $loop++
  40.     $time = Get-Date -format "HH:mm"
  41.     $timetaken = ((Get-Date)-$loopstart)
  42.     $totalfixes = $totalfixes + $fixes
  43.     Write-host "--------------------------------------------------"
  44.     Write-host "$time Completed loop $loop in " $timetaken.hours "hours, "$timetaken.minutes "minutes, "$timetaken.seconds" seconds."
  45.     Write-Host "Fixes this loop: $fixes. Overall fixes: $totalfixes"
  46.     Write-host "Waiting $wait seconds before continuing"
  47.     Write-host "--------------------------------------------------"
  48.     Start-Sleep -s $wait
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement