proxy-setup-spinner/vms/spin-a9d4ca52-ebb0-4d12-a885-d1bf142f5726_px.ps1

43 lines
1.4 KiB
PowerShell
Raw Normal View History

2024-02-07 23:57:14 +02:00
$imageUrl = "http://www.ngtech.co.il/static/cloud-images/jammy-server-cloudimg-amd64.vhdx"
$seedUrl = "http://10.50.1.100/config/a9d4ca52-ebb0-4d12-a885-d1bf142f5726/a9d4ca52-ebb0-4d12-a885-d1bf142f5726-cloud-init-data.iso"
$imageFileName = "jammy-server-cloudimg-amd64.vhdx"
$user = "a9d4ca52-ebb0-4d12-a885-d1bf142f5726_px"
$password = "e5020a9d-2b68-4740-a686-49f4a7335179"
$vmnet = "AWS_Cloud1"
$userPassPair = $user + ":" + $password
$vmdisk = ".\px-sys-disk.vhdx"
$vmseed = ".\seed.iso"
$vmname = "AWS_a9d4ca52-ebb0-4d12-a885-d1bf142f5726"
mkdir $vmname
cd $vmname
if ( Test-Path("..\images\" + $imageFileName)) {
Write-Output "Copying image locally"
Copy-Item ("..\images\" + $imageFileName) -Destination $vmdisk
Write-Output "Finished copying image locally"
} else {
Write-Output "Downloading image from a remote server"
Invoke-WebRequest -Uri $imageUrl -OutFile $vmdisk
Write-Output "Finished downloading image from a remote server"
}
Write-Output "Downloading seed image from a remote server"
Invoke-WebRequest -Uri $seedUrl -OutFile $vmseed -Headers @{ Authorization = "Basic "+ [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($userPassPair)) }
Write-Output "Finished downloading seed image from a remote server"
New-VM -Name $vmname -MemoryStartupBytes 2GB -Path . -BootDevice VHD -VHDPath $vmdisk -SwitchName $vmnet -Generation 1
Set-VMDvdDrive -VMName $vmname -Path $vmseed
Start-VM $vmname
cd ..