proxy-setup-spinner/vms/spin-4f936f1e-a410-4681-b4ec-daa8ec44c9e1_px.ps1
Eliezer Croitoru d7ec0d2317 1
2024-02-07 23:57:14 +02:00

43 lines
1.4 KiB
PowerShell

$imageUrl = "http://www.ngtech.co.il/static/cloud-images/jammy-server-cloudimg-amd64.vhdx"
$seedUrl = "http://10.50.1.100/config/4f936f1e-a410-4681-b4ec-daa8ec44c9e1/4f936f1e-a410-4681-b4ec-daa8ec44c9e1-cloud-init-data.iso"
$imageFileName = "jammy-server-cloudimg-amd64.vhdx"
$user = "4f936f1e-a410-4681-b4ec-daa8ec44c9e1_px"
$password = "a5da948a-1e0a-4a84-8c0b-359fb234d1a6"
$vmnet = "Alibaba_Cloud1"
$userPassPair = $user + ":" + $password
$vmdisk = ".\px-sys-disk.vhdx"
$vmseed = ".\seed.iso"
$vmname = "ALIBABA_4f936f1e-a410-4681-b4ec-daa8ec44c9e1"
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 ..