Skip to content

Instantly share code, notes, and snippets.

@blha303
Created March 14, 2015 04:17
Show Gist options
  • Save blha303/5be46163af65e8435e7e to your computer and use it in GitHub Desktop.
Save blha303/5be46163af65e8435e7e to your computer and use it in GitHub Desktop.
Set up test vm in hyper-v
function Connect-VM {
param(
[Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)]
[Microsoft.HyperV.PowerShell.VirtualMachine[]]$VM,
[switch] $PassThru
)
PROCESS {
foreach ($VMobject in $VM) {
vmconnect localhost ($VMobject.name)
}
if($PassThru) {$_}
}
}
new-vmswitch -name Int
new-vm -name 'testvm' -MemoryStartupBytes 1GB -SwitchName Int
add-vmdvddrive testvm -path "t:\wineval\8.1 Eval.iso"
new-vhd -dynamic c:\testvm.vhdx -sizebytes 20GB
Add-VMHardDiskDrive testvm -path c:\testvm.vhdx
get-vm -name testvm | start-vm -passthru | connect-vm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment