CARLSTEBEN
Contributor
Contributor

Powercli to change Startconnected to true

Hi !  New to powercli ..

I need a script to change the Startconnected to true on a specific folder and subfolder on vcenter.

0 Kudos
3 Replies
LucD
Leadership
Leadership

You mean something like this?

$folderName = 'MyFolder'

Get-Folder -Name $folderName |
Get-VM | Get-NetworkAdapter |
Set-NetworkAdapter -StartConnected:$true -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
CARLSTEBEN
Contributor
Contributor

It's working for a bunch but also getting error

 

PowerCLI C:\> $folderName = 'CDM'
PowerCLI C:\> Get-Folder -Name $folderName |
>> Get-VM | Get-NetworkAdapter |
>> Set-NetworkAdapter -StartConnected:$true -Confirm:$false
Get-VM : 2021-10-22 10:11:18 AM Get-VM Exception has been thrown by the target of an invocation.
At line:2 char:1
+ Get-VM | Get-NetworkAdapter |
+ ~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM


Name Type NetworkName MacAddress WakeOnLan
Enabled
---- ---- ----------- ---------- ---------
Network adapter 1 Flexible DPortGrou... 00:50:56:a2:6c:c2 True
Network adapter 1 Flexible DPortGrou... 00:50:56:a2:fa:8f True
Network adapter 1 Vmxnet3 DPortGrou... 00:50:56:a2:03:4d True
Network adapter 1 Flexible DPortGrou... 00:50:56:a2:d9:71 False
Network adapter 1 e1000e DPortGrou... 00:50:56:a2:2f:d6 True
Network adapter 1 Vmxnet3 DPortGrou... 00:50:56:a2:4f:29 True
Network adapter 1 Vmxnet3 DPortGrou... 00:50:56:a2:8d:85 True
Network adapter 2 Vmxnet3 DPortGrou... 00:50:56:a2:c0:90 True
Network adapter 1 Vmxnet3 DPortGrou... 00:50:56:a2:78:8a True

0 Kudos
LucD
Leadership
Leadership

Do you have multiple connections open?
Check what is in $global:defaultVIServers.
Sometimes it helps stopping/starting your PS session.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos