I’ve been working on a script to make a VM, and this is the segment that’s busting my balls.
$VMName = "Unifi" $VMSwitch = Get-VMSwitch -SwitchType External | Format-List -Property Name Get-VMNetworkAdapter -VMName $VMName | Connect-VMNetworkAdapter -SwitchName "$VMSwitch"
Basically, in 99.9% of the places I’ll be deploying this VM, there’s only one external vSwitch on the host. So, I figured it would be easiest to just fetch the external vSwitch and feed it into a variable which would be used in line 3. Using just
$VMSwitch = Get-VMSwitch -SwitchType External
Results in errors, so I figured I’d try using format-list and only include the name property (which is what connect-vmnetworkadapter wants), which when running that variable on it’s own seems to work. when using format-list I get this mess.
Does anyone have any advice on how to get this to work?
submitted by /u/thatoneguyyouknow3
[link] [comments]
The post Connect-VMNetworkAdapter problems appeared first on How to Code .NET.