Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick and dirty function to download VMs from http://Modern.ie and trigger extraction
<#
.EXAMPLE
Get the "Batch File Download" address for the (Hyper-V) VM of your choice from https://modern.ie/en-gb/virtualization-tools#downloads
PS> $source = "https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/HyperV_2012/IE11/Windows/IE11.Win7.For.Windows.HyperV_2012.txt"
PS> $destination = (mkdir "$env:USERPROFILE\downloads\vms" -Force) # or use default
PS> Install-IEVM $source $destination -import # Will import to default locations
#>
Function Install-IEVM {
param(
[Parameter(Mandatory=$true)]
[string]$source,
[string]$destination = (mkdir "$env:USERPROFILE\Virtual Machines" -Force),
[switch]$import
)
# Download
$entries = (Invoke-WebRequest $source).content -split [Environment]::NewLine | ? { ![string]::IsNullOrWhiteSpace($_) }
$entries | % {
Start-BitsTransfer $_ $destination -Description "Downloading - $_" -DisplayName "Downloading Virtual Machine"
}
# Compose zip
$leaves = ($entries | split-path -leaf )
$zipname = $leaves[0] -replace '(.+)\.zip\.001$','$1'
Push-Location $destination
# Combine the downloads
cmd /c "copy /b $($leaves -join ' + ') $zipname.zip"
$imported = $null
if($import -or $start){
# Extract
$shell = new-object -com shell.application
$zip = $shell.NameSpace("$destination\$zipname.zip")
$extractDest = mkdir $zipname -Force
foreach($item in $zip.items())
{
$shell.Namespace($extractDest.FullName).copyhere($item)
}
# Import into Hyper V
$machine = Get-Item "$extractDest\Virtual Machines\*.xml" | select -First 1
if($machine){
# From the Hyper-V module
$imported = Import-VM $machine -Copy # Import the virtual machine to the default locations
} else {
Write-Warning "No virtual machine configuration found - Import cancelled"
}
}
Pop-Location
Write-Host Complete
if($imported) { return $imported }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.