Hello, I knew to CLI and have done only a little powershell. I need to change some adapter settings using CLI, however its not working. Here is what I need to do and what commands I am trying. The VM has 2 adapters that I need to put on different port groups.
Need to change:
Adapter 1 - Network Name - need to change the portgroup to VLAN 1
Adapter 2 - Network Name - need to change to portgroup to VLAN 2
Start connect - true
wakeonlan - true
connect - true
The command I am using is (this is from older thread on here). This if for Network Adapter 1
Get-NetworkAdapter -VM test-server1 | where {$_.Name -eq "Network Adapter 1"} | Set-NetworkAdapter -NetworkName "Vlan 1" -Confirm:$false
-- when I run this command, it returns the cursor to a >> I think its waitin for input but do not know. Get-NetworkAdapter -VM test-server1 | where {$_.Name -eq "Network Adapter 1"} | Set-NetworkAdapter -WakeOnLan:$true - StartConnected:$true -Connected:$true
-- I get the same >>_______
So what I am doing wrong?
I did print off the powerCLI adiminstrator guide and reading it now.
If anyone has a better command to run that will change the I can specify a network adapter and then change port group and make sure its connect, please let me know.
Thanks.
In that case;
Is the VLAN available on the host where vmtest-1 is running?
Can you try adding -Confirm:$false and see if that resolves the problem?
Check first if
Get-NetworkAdapter -VM test-server1 | where {$_.Name -eq "Network Adapter 1"}
returns an object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did have a missing }, which I fixed but did not work.
I check to see if Get-NetworkAdapter -VM test-server1 | where {$_.Name -eq "Network Adapter 1"} would return an object and it does return Network Adapter 1. -- Thanks for this idea
I do have a -Confirm:$false at the end but not work.
However, fixing the { } fixed the it going to >>
However, I am still getting an error, now it is an error after the the | Set-Networkadapter -NetworkName "Vlan 1"
It states a general system error with that line, its erroring on the "Set-NetworkAdapter"
There is a space between the dash and StartConnected "- StartConnected:$true"
Thanks Nielse, that fixed the line to get the adapters connected.
I am still having an issue with this line.
Get-NetworkAdapter -VM test-server1 | where {$_.Name -eq "Network Adapter 1"} | Set-NetworkAdapter -NetworkName "Vlan 1" -Confirm:$false
If I run Get-NetworkAdapter -VM test-server1 | where {$_.Name -eq "Network Adapter 1"} It does return a value for Network adapter 1. However it errors on Set-NetworkAdapter -NetworkName "Vlan 1"
Is there a simple command I could do to call out Network adapter 1 and set network name?
Could you paste the error by any chance?
I have to type it.
"Set-NetworkAdapter A general system error occured: Not initailized at line:1 char:99
+ Get-NetworkAdapter -VM testvm1 | where {$_.Name -eq "Network Adapter 1"} | Set-NetworkAdapter <<<< -NetworkName "VLAN 1" -Confirm:$false
+ Catagoryinfo : NotSpecified: (:) [Set-NetworkAdapter]. VMException
+ FullyQualifedErrorId : Core_BaseCmdlet_UnknownError.VMWare.VimAutomation.VICore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter
Line 99 - the beginning of Set-NetworkAdapter
I redid my command little.
Get-VM vmtest-1 | Get-NetworkAdapter | where { $_.NetworkName -eq ‘Network adapter 1’ } | Set-NetworkAdapter -NetworkName “VLAN 1”
it did come up with me to confirm, i said yes.
then it errors, with the general system error: not iniatilized at line 1 char 104
Can you try replacing the ' with " quotes?
Get-VM vmtest-1 | Get-NetworkAdapter | where { $_.NetworkName -eq "Network adapter 1" } | Set-NetworkAdapter -NetworkName “VLAN 1”
Same error whether I use ' or ".
I am using " " now for both network adapter and vlan 1
Can you try:
Get-VM vmtest-1 | Get-NetworkAdapter -Name "Network adapter 1" | Set-NetworkAdapter -NetworkName “VLAN 1”
Message was edited by: nielse
I did your command Get-VM vmtest-1 | Get-NetworkAdapter -Name "Network adapter 1" | Set-NetworkAdapter -NetworkName “VLAN 1”
I came up with a confirmation. I selected yes.
then I get the same error.
Set-NetworkAdapter A general system error occured: Not intialized at line 1 char:88
* Get-VM vmtest-1 | Get-NetworkAdapter -Name "Network adapter 1" | Set-NetworkAdapter <<<< -NetworkName “VLAN 1”
+ CatagoryInfo : NotSpecificed: (:) [Set-NetworkAdapter], VimException
+ FullyQualifedErrorID : Core_BaseCMDlet_UnknownError.VMWare.VimAutomation.ViCore.Cmdlets.Commands.VirtualizedDevice.SetNetworkAdatper
Ok, I ran your command Get-VM vmtest-22 | Get-NetworkAdapter -Name "Network adapter 1" | Set-NetworkAdapter -NetworkName “VLAN 8”
I changed the VM and the Vlan and it worked.
so the command is fine, its something with the adapters on vmtest-1 I think.
Could you paste the whole script?
Also are you only once connected to your vCenter?
Disconnect-VIServer then type A
Then try Connect-VIServer localhost and try the command again
In that case;
Is the VLAN available on the host where vmtest-1 is running?
I am gonig to remove both network adapters on vmtest-1 and re-create them.
Anyone have a command to remove a network adapter and then create one?
going to look in the admin book.
Good point, I will test this before I delete.
Looking at the Networking section in VMSphere.
Our distributed switch name: DSwitch1
with vlans 1, vlan 2, vlan 3 ...
I look at the Ports on the switch and do not see my vmtest-1 under any Port ID's. Do I need to assign it a port ID before I can move to different vlans?
if so, how do i assign it a port id? is a pord id same as portgroup? Everything I am reading says how to assign a portgroup but I do not see anything in our network that says portgroups.
Ok, you are on a dvSwitch, that's another story.
Have a look at my dvSwitch scripting – Part 12 – Find free ports post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference