<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need to run script/python command against ESXi hosts in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968470#M111949</link>
    <description>&lt;P&gt;The esxcli command you can do via the &lt;A href="https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/get-esxcli/" target="_blank" rel="noopener"&gt;Get-EsxCli&lt;/A&gt; cmdlet, for the mv and python commands you will need to use SSH I'm afraid.&lt;BR /&gt;With the &lt;A href="https://www.powershellgallery.com/packages/Posh-SSH/3.0.8" target="_blank" rel="noopener"&gt;Posh-SSH&lt;/A&gt; module you can do that from your script.&lt;BR /&gt;&lt;BR /&gt;See for example&amp;nbsp;&lt;A href="https://www.lucd.info/knowledge-base/use-posh-ssh-instead-of-putty/" target="_blank" rel="noopener"&gt;Use Posh-SSH instead of PuTTY&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 15 May 2023 11:12:58 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2023-05-15T11:12:58Z</dc:date>
    <item>
      <title>Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968469#M111948</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to run the following commands against 2 clusters of hosts, 26 in total, all contained in 1 VC:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mv /vmfs/volumes/WB01-INF03-PMAX-DS01/ucs-tool-esxi_1.2.1-1OEM.zip /tmp&lt;/P&gt;&lt;P&gt;esxcli software component apply -d /tmp/ucs-tool-esxi_1.2.1-1OEM.zip&lt;/P&gt;&lt;P&gt;python /opt/ucs_tool_esxi/ucs_host_inventory.py&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone point me in the right direction to do this in PS? I dont want to ssh into all of the hosts. Thank You!&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 11:08:14 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968469#M111948</guid>
      <dc:creator>PSScripter</dc:creator>
      <dc:date>2023-05-15T11:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968470#M111949</link>
      <description>&lt;P&gt;The esxcli command you can do via the &lt;A href="https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/get-esxcli/" target="_blank" rel="noopener"&gt;Get-EsxCli&lt;/A&gt; cmdlet, for the mv and python commands you will need to use SSH I'm afraid.&lt;BR /&gt;With the &lt;A href="https://www.powershellgallery.com/packages/Posh-SSH/3.0.8" target="_blank" rel="noopener"&gt;Posh-SSH&lt;/A&gt; module you can do that from your script.&lt;BR /&gt;&lt;BR /&gt;See for example&amp;nbsp;&lt;A href="https://www.lucd.info/knowledge-base/use-posh-ssh-instead-of-putty/" target="_blank" rel="noopener"&gt;Use Posh-SSH instead of PuTTY&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 11:12:58 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968470#M111949</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-15T11:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968472#M111950</link>
      <description>&lt;P&gt;Thanks, Ill check out Posh-SSH&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 11:15:33 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968472#M111950</guid>
      <dc:creator>PSScripter</dc:creator>
      <dc:date>2023-05-15T11:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968476#M111951</link>
      <description>&lt;P&gt;Here is what I came up with, I have not used it yet..but I think it will work &lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@3CBC42A1E7848F607FD419D398107BF9/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Connect-VIServer 'XXXXXXXXXXXXX'

$hosts = Get-Cluster "XXXXXXXXXX" | Get-VMHost
$cred = Get-Credential
$cmd = "mv /vmfs/volumes/INF03-PMAX-DS01/ucs-tool-esxi_1.2.1-1OEM.zip /tmp"
$cmd1 = "python /opt/ucs_tool_esxi/ucs_host_inventory.py"
    
foreach ($host in $hosts) {

    Get-VMHost $host | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" } | Start-VMHostService
    $session = New-SSHSession -ComputerName $host -Credential $cred -AcceptKey
    Invoke-SSHCommand -SSHSession $session -Command $cmd
    Get-esxcli software component apply -d /tmp/ucs-tool-esxi_1.2.1-1OEM.zip
    Invoke-SSHCommand -SSHSession $session -Command $cmd1 
    
    Remove-SSHSession -SSHSession $session | Out-Null 

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts on that piece of work lol?&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 12:43:53 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968476#M111951</guid>
      <dc:creator>PSScripter</dc:creator>
      <dc:date>2023-05-15T12:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968499#M111954</link>
      <description>&lt;P&gt;I'm still trying to get this working correctly. Here is my latest, and the error I am getting:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Connect-VIServer 'XXXXXXXXXXXXX'

$hosts = Get-Cluster -name "XXXXXXXXXXX" | Get-VMHost
$cred = Get-Credential
$cmd = "mv /vmfs/volumes/INF03-PMAX-NonProd-DS01/ucs-tool-esxi_1.2.1-1OEM.zip /tmp"
$cmd1 = "python /opt/ucs_tool_esxi/ucs_host_inventory.py"
$arguments = @{
    'VIBURL' = '/tmp/ucs-tool-esxi_1.2.1-1OEM.zip'
}
    
foreach ($esx in $hosts) {

    # Get-VMHost $esx | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" } | Start-VMHostService
    $session = New-SSHSession -ComputerName $esx -Credential $cred -AcceptKey
    Invoke-SSHCommand -SSHSession $session -Command $cmd

    $esxcli = Get-EsxCli -VMHost $esx
    $esxcli.software.component.apply.Invoke($arguments)

    Invoke-SSHCommand -SSHSession $session -Command $cmd1 
    Remove-SSHSession -SSHSession $session | Out-Null 

}&lt;/LI-CODE&gt;&lt;P&gt;The copy seems to work, but the esxcli command is failing with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MethodInvocationException: C:\Temp\vSphere\Install-UCSTools.ps1:19
Line |
  19 |      $esxcli.software.component.apply.Invoke($arguments)
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Invoke" with "1" argument(s): "A specified parameter was not correct: argument[1]"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts on how I can get this working?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 13:45:53 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968499#M111954</guid>
      <dc:creator>PSScripter</dc:creator>
      <dc:date>2023-05-15T13:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968515#M111956</link>
      <description>&lt;P&gt;This seems to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Connect-VIServer 'XXXXXXXXXXXXX'

$hosts = Get-Cluster -name "XXXXXXXXXXX" | Get-VMHost

$cred = Get-Credential
$cmd = "mv /vmfs/volumes/INF03-PMAX-NonProd-DS01/ucs-tool-esxi_1.2.1-1OEM.zip /tmp"
$cmd1 = "python /opt/ucs_tool_esxi/ucs_host_inventory.py"
$arguments = @{
    'VIBNAME' = '/tmp/ucs-tool-esxi_1.2.1-1OEM.zip'
}
    
foreach ($esx in $hosts) {

    Get-VMHost $esx | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" } | Start-VMHostService
    $session = New-SSHSession -ComputerName $esx -Credential $cred -AcceptKey
    Invoke-SSHCommand -SSHSession $session -Command $cmd

    $esxcli = Get-EsxCli -VMHost $esx
    $esxcli.software.vib.install("/tmp/ucs-tool-esxi_1.2.1-1OEM.zip")

    Invoke-SSHCommand -SSHSession $session -Command $cmd1 
    Remove-SSHSession -SSHSession $session | Out-Null 

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 14:08:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968515#M111956</guid>
      <dc:creator>PSScripter</dc:creator>
      <dc:date>2023-05-15T14:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run script/python command against ESXi hosts</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968524#M111959</link>
      <description>&lt;P&gt;To use the Invoke method, you have to add the V2 switch&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$esxcli = Get-EsxCli -VMHost $esx -V2&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 15 May 2023 14:19:49 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-to-run-script-python-command-against-ESXi-hosts/m-p/2968524#M111959</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-15T14:19:49Z</dc:date>
    </item>
  </channel>
</rss>

