From b0496202047ddc26dc421f2c32793361cf198a9e Mon Sep 17 00:00:00 2001 From: Adam Bertram Date: Mon, 14 Dec 2015 11:08:28 -0600 Subject: [PATCH] new script --- Hyper-V/Checkpoint-OnlineVM.ps1 | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Hyper-V/Checkpoint-OnlineVM.ps1 diff --git a/Hyper-V/Checkpoint-OnlineVM.ps1 b/Hyper-V/Checkpoint-OnlineVM.ps1 new file mode 100644 index 0000000..81c7a97 --- /dev/null +++ b/Hyper-V/Checkpoint-OnlineVM.ps1 @@ -0,0 +1,35 @@ +function Checkpoint-OnlineVM +{ + <# + .SYNOPSIS + This function checks to see if a VM is running and if so, shuts it down and creates a checkpoint. If it's not running, + it will go ahead and create the checkpoint. + + .PARAMETER VM + A virtual machine. + + .EXAMPLE + PS> Get-VM -Name SERVER1 | Checkpoint-OnlineVM + + This will find the VM called SERVER 1. If it's running, it will shut it down and create a checkpoint. If it's not + running, it will simply create a checkpoint. + #> + + [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High')] + param + ( + [Parameter(Mandatory, ValueFromPipeline)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]]$VM + ) + process + { + foreach ($v in $VM) + { + if ($PSCmdlet.ShouldProcess($v.Name,'VM shutdown')) + { + $v | Stop-VM -Force -PassThru | Checkpoint-VM + } + } + } +} \ No newline at end of file