Created
May 3, 2022 15:41
-
-
Save r4rohan/93c58e506d99aa0c9a5479aa2cb482b8 to your computer and use it in GitHub Desktop.
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
# this file only contains function logic of GCE Machine Image for Windows VM. | |
# for full code visit: https://github.com/r4rohan/cloud-scripts/blob/main/scripts/windows/windows-machine-image.ps1 | |
. | |
. | |
. | |
function Machine_Image | |
{ | |
param | |
( | |
[string] $vmName, | |
[string] $zone | |
); | |
process | |
{ | |
$zone = Get-Zone; | |
$Tdate=Get-Date -UFormat "%m%d%Y%H%M%S" | |
$arguments = @( | |
"compute", | |
"machine-images", | |
"create", | |
"$vmName-$Tdate", | |
"--source-instance $vmName", | |
"--source-instance-zone $zone" | |
); | |
$process = Invoke-Gcloud -Arguments $arguments; | |
if($process.ExitCode -ne 0) | |
{ | |
return $false; | |
} | |
return $true; | |
} | |
} | |
$vmName = Get-VmName; | |
$zone = Get-Zone; | |
Write-Host -NoNewline "Creating Machine Image: "; | |
$result = Machine_Image -VmName $vmName -Zone $zone; | |
if($result) | |
{ | |
Write-Host "done"; | |
} | |
else | |
{ | |
Write-Host "failed"; | |
# Return non-zero exit code to stop patching | |
[System.Environment]::Exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment