PowerCLI

  • 1.  Powercli in Powershll

    Posted Feb 21, 2022 09:50 PM

    Hello,

    I am new to scripting world.

    Is there anyway I can use the powercli commands in powershell?

    I was trying to add welcome note for an ESXi host via powershell by the below commands. And I am struggling for that. Can someone please help me how to do it via powershell (not via putty)

    $esxcli = Get-EsxCli -VMhost <ESXi host name> -V2

    $esxcli.system.settings.advanced.welcomemsg.get()

    $esxcli.system.settings.advanced.welcomemsg.set('Hi')

    NeenaJim_0-1645480010634.png

    This is what I am getting:

    NeenaJim_0-1645480632214.png

     



  • 2.  RE: Powercli in Powershll
    Best Answer

    Posted Feb 21, 2022 10:12 PM

    When you use the V2 switch, you have to use the Invoke() method
    The parameters are passed in a hash table (for which you can get a template with the CreateArgs() method)

    $esxcli = Get-EsxCli -VMhost <ESXi host name> -V2
    $esxcli.system.welcomemsg.get.Invoke()
    $esxcli.system.welcomemsg.set.Invoke(@{message='Hi'})

    .
     



  • 3.  RE: Powercli in Powershll

    Posted Feb 22, 2022 01:04 AM

    That works. Thank you very much. You the BEST!