Take a snapshot with standardized naming

As with everything in IT, having things standardized generally makes your life easier. Unfortunately in many environments, snapshots tend to get overlooked and their naming convention can end up a little adhoc which can lead to confusion around who and why they were taken.
Ive put together the following script which takes a snapshot with certain key information included e.g

Snapshot Name = CurrentUser TicketNumber Date
Tony 101010 01/06/2019

While you can get the date by clicking on the snapshot, i felt it would make it easier to find the one you require on VMs with several snapshots taken.

Function Name – VPF-TakeSnapshot

<code>Function VPF-TakeSnapshot
{
$CU = $global:DefaultVIServer.User
$VM = Read-Host " Please enter a VM name"
write-host
get-vm $vm | select Name, notes 
write-host
$CorrectVM = Read-Host " Is this the correct VM? (Y/N)"
IF ($CorrectVM -eq "Y" {
	clear
	$Ticket = Read-Host " Please enter a Ticket Number"
	$Description = Read-Host " Please enter a snapshot Description"
	New-Snapshot -VM $VM -Name "$CU - $Ticket - $(get-date -f yyyy-MM-dd)" -Description "$Description"
		Write-Host -NoNewLine " Snapshot Complete, Press any key to continue...";
		$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
	}
Else {
		$VMs = get-vm $VM
		Write-Host
		Write-Host " ================ Select VM ================"  -ForegroundColor green
		Write-Host
		$i = 1
		$VMs | ForEach-Object -Process {
		Write-Host " $i $($_.Name)  $($_.Notes) "
		$i++
	}
		Write-Host
		Write-Host
		$selection = Read-Host " Please make a selection (Q to Quit)"

	if($selection -eq 'Q'){
		 clear
         Exit
}
	else{
    $VMChoice = $VMs&#91;$selection -1].Name
	$Ticket = Read-Host " Please enter a Ticket Number"
	$Description = Read-Host " Please enter a snapshot Description"
	New-Snapshot -VM $VM -Name "$CU - $Ticket - $(get-date -f yyyy-MM-dd)" -Description "$Description"
		Write-Host -NoNewLine " Snapshot Complete, Press any key to continue...";
		$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
	}
 }
}</code>

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.