<< A B C D E F G H I J K L M N O P Q R S T U V W X Y Z






external adapter, create

Assume we don't know which network adapter we have that has an internet connection. So, this

Get-WmiObject win32_networkAdapterConfiguration | Where defaultIPGateway -ne $null | Select-Object -Property Description | Out-GridView -PassThru | ForEach-Object -Process {
    $Splat = @{
        NetAdapterInterfaceDescription = $_.Description
        Name = "PSEExternal"
        AllowManagementOS = $true
        Notes = "External Switch for the Sandbox"
        Verbose = $true
    New-VMSwitch @Splat

Unfortunately, when I ran this, it only found one Internet connection. And after that, my PC couldn't connect to the Internet anymore. So I had to kill it through Hyper-V interface. I suspect the reason was I already had a default switch already set up.




health of a virtual machine

Get-VM -VMName fs0 | select Name, State, Status

host of a virtual machine, see virtual machine's host

Hyper-V host of a virtual machine, see virtual machine's host












switch, create

New-VMSwitch -Name PSTest -SwitchType Private -Notes "Switch for test machine"




virtual machine's host

(Get-Item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")

VM, create

$VHDPath = "D:\VM"
$Names = "DC", "SVR1"
ForEach ($name in $Names)
    $VMHash = @{BootDevice = "CD"
                MemoryStartUpBytes = 512MB
                Name = $Name
                SwitchName = "Default Switch"
                NewVHDPath = "$($VHDPath)\$($Name).vhdx"
                NewVHDSizeBytes = 10GB
                Verbose = $true
    New-VM @VMHash

VM, start

# Get the VM objects
$VMs = Get-VM -VMName DC, SVR1
# Get the name of the local host.
$Hostname = hostname
# Make sure each VM is started and connect to it.
ForEach ($VM in $VMs)
    If ($VM.State -ne "Running")
        Start-VM -VMName $VM.Name
        Invoke-Expression -Command "VMConnect $($Hostname) $($VM.Name)"
        Invoke-Expression -Command "VMConnect $($Hostname) $($VM.Name)"

VM DVD drive, point to the ISO file

# Configure the DVD drive to point to the ISO file.
$ISOPath = "D:\Downloads\SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_English_-2_MLF_X21-22843.ISO"
Set-VMDvdDrive -VMName DC -Path $ISOPath -Verbose
Set-VMDvdDrive -VMName SVR1 -Path $ISOPath -Verbose

VM memory, allocate

$VMMemoryHash = @{
    DynamicMemoryEnabled = $true
    MaximumBytes = 1024MB
    MinimumBytes = 512MB
Get-VM -Name DC, SVR1 | Set-VMMemory @VMMemoryHash