Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. asnp Citrix*
  2. $Bad = ""
  3.  
  4. $date = Get-Date
  5. $numofmins = 20
  6.  
  7. $VMName = Get-VM -Name *p*t* -ComputerName (Get-ClusterNode -Cluster CLUSTER) | select -ExpandProperty Name
  8.  
  9. foreach ($VM in $VMName) {
  10.     $CitrixVM = Get-BrokerDesktop -AdminAddress 10.1.1.11 -MachineName "LHI\$VM"
  11.  
  12.     $MailMessage = @{
  13.         To = "support@nextstepta.com"
  14.         From = "robot@lh-inc.com"
  15.         Body = "Please make sure the VMs are restarted. The script should have restarted the virtul machine(s)."
  16.         Smtpserver = "10.1.1.51"
  17.         ErrorAction = "SilentlyContinue"
  18.     }
  19.    
  20.     if ($CitrixVM.RegistrationState = "Unregistered") {
  21.             if($CitrixVM.LastDeregistrationTime -le $Date.AddMinutes(-$numofmins)) {
  22.                 $Bad = $CitrixVM.MachineName
  23.                 Send-MailMessage @MailMessage -Port 25 -Subject "Citrix VM down.. $bad"
  24.                 Stop-VM -Name $VM -Force
  25.                 Start-Sleep -Seconds 10
  26.                 Start-VM -Name $VM
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement