Automation

 View Only
  • 1.  Powercli script to Set-NetworkAdapter

    Posted Mar 04, 2024 04:21 PM

    Hi, I am new to powershell and I am having difficulties getting a script to set StartConnected to true only on VMs in a cluster where the power state of the VM is on. Anyone have any suggestions?



  • 2.  RE: Powercli script to Set-NetworkAdapter
    Best Answer

    Posted Mar 04, 2024 04:34 PM

    Try something like this

    Get-Cluster -Name MyCluster |
    Get-VM | 
    Where{$_.PowerState -eq 'PoweredOn'} |
    Get-NetworkAdapter |
    Set-NetworkAdapter -StartConnected:$true -Confirm:$false
    


  • 3.  RE: Powercli script to Set-NetworkAdapter

    Posted Mar 04, 2024 04:43 PM

    Thank you, that worked!



  • 4.  RE: Powercli script to Set-NetworkAdapter

    Posted Mar 04, 2024 05:58 PM

    One last question, I notice I get this error when running the script but it seems to still enable the setting, is this normal:

    Set-NetworkAdapter : 3/4/2024 12:55:22 PM Set-NetworkAdapter Operation is not valid due to the current state of the object.
    At line:6 char:1
    + Set-NetworkAdapter -StartConnected:$true -Confirm:$false
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Set-NetworkAdapter], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

     

     



  • 5.  RE: Powercli script to Set-NetworkAdapter

    Posted Mar 04, 2024 06:02 PM

    Unfortunately the VM needs to powered off to change this setting.
    You will have to adapt the Where-clause to check for the PoweredOff state.