ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Iterate systems with a timer

    Scheduled Pinned Locked Moved IT Discussion
    1 Posts 1 Posters 199 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • GreyG
      Grey
      last edited by

      I needed to iterate through a list of systems that I'd placed in to a text file so I could shut them off, perform work on each one through vsphere and return it to service without just taking them all down immediately. The countdown gives me the opportunity to do the work and turn the vm back on.

      $file = "$($ENV:USERPROFILE)\desktop\systems.txt"
      $systems = get-content $file
      foreach ($guest in $Systems){
              Write-Host -foregroundcolor cyan "``nStopping $($guest)."
              Stop-Computer -ComputerName $guest
      #On-screen Timer
      $delay = 280
      $Counter_Form = New-Object System.Windows.Forms.Form
      $Counter_Form.Text = "Countdown Timer!"
      $Counter_Form.Width = 450
      $Counter_Form.Height = 200
      $Counter_Label = New-Object System.Windows.Forms.Label
      $Counter_Label.AutoSize = $true 
      $Counter_Form.Controls.Add($Counter_Label)
      while ($delay -ge 0)
      {
        $Counter_Form.Show()
        $Counter_Label.Text = "Seconds Remaining: $($delay)"
        start-sleep 1
        $delay -= 1
      }
      $Counter_Form.Close() 
      }
      

      Recorded here for future use and/or sharing. Counter from here.

      1 Reply Last reply Reply Quote 3
      • 1 / 1
      • First post
        Last post