Skip to content

Instantly share code, notes, and snippets.

@Kieranties
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kieranties/6099b5898ba1c6a998a8 to your computer and use it in GitHub Desktop.
Save Kieranties/6099b5898ba1c6a998a8 to your computer and use it in GitHub Desktop.
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