Hello y’all,
So I’ve been trying to select the first network card on my server and setting that as a variable to allow the out put to be used on a different command. I’m able to get the first nic but when I try to us it in the other command I get an error stating “Sequence contains no matching element”
My goal is to automate the creation of a VM in Hyper-V. First step is to make the Virtual switch.
The command I’m using is “$NIC = Get-NetAdapter | Select-Object -First 1 -Property InterfaceDescription”. This sets the “$NIC” to the output of the command. I then try to use the above in “New-VMSwitch -Name “VM Switch” -NetAdapterInterfaceDescription $NIC” which is when I get the following error :
New-VMSwitch : Sequence contains no matching element
At line:2 char:1
- New-VMSwitch -Name “VM Switch” -NetAdapterInterfaceDescription $NIC
-
+ CategoryInfo : InvalidOperation: (:) [New-VMSwitch], VirtualizationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.HyperV.PowerShell.Commands.NewVMSwitch
I think the issue is the the “InterfaceDescription” showing up above the nic I need but I can’t seem to find a way to remove that from the output. Is it even possible to remove that bit of the out put?
PS: I’m not a wiz at powershell.