Skip to content

Commit

Permalink
new script
Browse files Browse the repository at this point in the history
  • Loading branch information
adbertram committed Dec 14, 2015
1 parent f531257 commit b049620
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Hyper-V/Checkpoint-OnlineVM.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}

0 comments on commit b049620

Please sign in to comment.