43 lines
1.4 KiB
PowerShell
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/183f199c-bdc6-408a-8286-d04afc3ab0f9/183f199c-bdc6-408a-8286-d04afc3ab0f9-cloud-init-data.iso"
|
|
$imageFileName = "jammy-server-cloudimg-amd64.vhdx"
|
|
|
|
$user = "183f199c-bdc6-408a-8286-d04afc3ab0f9_px"
|
|
$password = "ca43b9de-4d37-4c4e-be91-80148f823f01"
|
|
|
|
$vmnet = "DigitalyOcean_Cloud1"
|
|
|
|
$userPassPair = $user + ":" + $password
|
|
|
|
$vmdisk = ".\px-sys-disk.vhdx"
|
|
|
|
$vmseed = ".\seed.iso"
|
|
|
|
$vmname = "DIGITALOCEAN_183f199c-bdc6-408a-8286-d04afc3ab0f9"
|
|
|
|
|
|
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 ..
|