-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm-pause.ps1
28 lines (23 loc) · 916 Bytes
/
vm-pause.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<#
.SYNOPSIS
Loop through all the powered on VMs in the vCenter server and pauses them.
.DESCRIPTION
Used if you need to quickly do maintence on the hosts or the datastores and don't want to cause any issues with dataloss
.NOTES
File Name : vm-pause.ps1
Author : Chris Roberts [email protected]
Prerequisite : PowerShell V2
.LINK
Script posted at:
http://github.com/chris1984/vmware-scripts
#>
# Connect to the VMware vCenter
Connect-VIServer -Server <vcenterfqdn> -User <adminuser> -Password <adminpassword>
# Get list of vm names that are going to be shut off
Get-VM |Where-object {$_.powerstate -eq "poweredon"} | Format-Table -AutoSize -Wrap
# Store that to a variable
$VMs = Get-VM |Where-object {$_.powerstate -eq "poweredon"}
# Put VMs into suspend mode
$VMs | Suspend-VM -Confirm:$false
# Disconnect from vCenter server
Disconnect-VIServer -Confirm:$false