Assume we don't know which network adapter we have that has an internet connection. So, this
- looks at all your network adapters
- If any of them has a gateway address, gives the option to use that interface card for our Internet connection
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
New-VMSwitch -Name PSTest -SwitchType Private -Notes "Switch for test machine"
(Get-Item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")
$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
}
# 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)"
}
else
{
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
$VMMemoryHash
=
@{
DynamicMemoryEnabled
=
$true
MaximumBytes
=
1024MB
MinimumBytes
=
512MB
}
Get-VM
-Name DC, SVR1 |
Set-VMMemory
@VMMemoryHash