Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---------------------------------------------------------------------
- # Date : 13-08-2013
- # Script name : Force_restart.ps1
- # Description : Restart disconnected desktops after 9 hours. Only desktops of a desktop group will be restarted.
- # PowerOff disconnected desktops after 10 hours. Only desktops of a desktop group will be restarted.
- #
- #
- # Extra module : citrix*
- # VMware.VimAutomation.Core
- # VMware.VimAutomation.Vds
- #
- # Copyright : ©2014 Login Consultants, all rights reserved.
- # History : RJA 20140812 Initial version
- # RJA 20140813 PowerOff added
- #---------------------------------------------------------------------
- # Import the required Snap-ins
- Add-PSSnapIn citrix*
- Add-PSSnapIn VMware.VimAutomation.Core
- Add-PSSnapIn VMware.VimAutomation.Vds
- # Query all VDI desktops that are in maintenance mode longer then 9 hours.
- $forcerebootmachines = Get-BrokerSession -SessionState Disconnected -Filter {SessionStateChangeTime -lt "-9:00"} -HypervisorConnectionName REPLACE WITH GROUP -DesktopGroupName "REPLACE WITH GROUP"| Select-Object HostedMachineName
- foreach ($item in $forcerebootmachines)
- {
- Restart-Computer -Force -computername $item.HostedMachineName
- }
- # Shutdown VDI desktops that do not respond to restart-computer
- $ConfirmPreference="none"
- Set-PowerCliConfiguration -invalidcertificateaction Ignore
- Connect-VIServer REPLACE WITH VSPHERE SERVER -notdefault
- $forcerebootmachines10 = Get-BrokerSession -SessionState Disconnected -Filter {SessionStateChangeTime -lt "-10:00"} -HypervisorConnectionName REPLACE WITH GROUP -DesktopGroupName "REPLACE WITH GROUP"| Select-Object HostedMachineName
- foreach ($item in $forcerebootmachines10)
- {
- Get-VM -Name $item.HostedMachineName | Stop-VM -Kill
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement