forked from adbertram/Random-PowerShell-Work
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |