VMware Cloud Community
yosingh
Enthusiast
Enthusiast

Patching ESXi hosts using Powercli script

I am trying to create a script to patch multiple ESXI hosts in a given file by uploading ESXi zip file to the datastore.
Please help me out on it.

$server= Get-Content "C:\temp\ESXi.csv"

$ESXi= $server| select Name

$hosts = $server| select -Last 1

$DS = get-vmhost $hosts| select -First 1 | Get-Datastore | Sort-Object CapacityGB | select Name, FreeSpaceGB, DatastoreBrowserPath -Last 1

$isosize = "40"  # ensuring datastore is having 10 times more free space.

$DSname = ($DS).Name

$DSpath = ($DS).DatastoreBrowserPath

$DS = ($DS).FreeSpaceGB

$Ds = [math]::Round($Ds)

if ($DS -gt $isosize){

    Write-Host -ForegroundColor Green Datatore: $DSname is having more than "40 GB" free space i.e $DS GB

     $source = "D:\ESXifile\ESXi6.7.zip"

     $filezip = "\ESXi6.7.zip"                       

     $fp = $DSpath + $filezip                          

     $result = Copy-DatastoreItem -Item $source -Destination $fp

   

    $v= get-vmhost $ESXi

    $v | Install-VMHostPatch -HostPath $fp

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

And what is the problem?
Are you getting any error messages?


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

Reply
0 Kudos
yosingh
Enthusiast
Enthusiast

Here is the error, i get error in last part while installing. i am not sure if first i need to unzip it and than upload it to the datastore ?

VMware-ESXi-6.7.0-8169922-depot.zip  file is available on given datastore. #upload was successful.

Message: EsxCLI.CLIFault.summary;

InnerText:  [MetadataDownloadError] Could not download from depot at

zip:/vmfs/volumes/ESXi_DS/VMware-ESXi-6.7.0-8169922-depot.zip?index.xml, skipping

(('zip:/vmfs/volumes/ESXi_DS/VMware-ESXi-6.7.0-8169922-depot.zip?index.xml', '', "Error extracting

index.xml from /vmfs/volumes/ESXi_DS/VMware-ESXi-6.7.0-8169922-depot.zip: [Errno 2] No such file or

directory: '/vmfs/volumes/ESXi_DS/VMware-ESXi-6.7.0-8169922-depot.zip'"))        url =

zip:/vmfs/volumes/ESXi_DS/VMware-ESXi-6.7.0-8169922-depot.zip?index.xml Please refer to the log file for

more details.EsxCLI.CLIFault.summary

At line:19 char:5

+     $InstallResponse = $esxcli2.software.vib.install.Invoke($CreateAr ...

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], MethodFault

    + FullyQualifiedErrorId : VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.MethodFault

Reply
0 Kudos
LucD
Leadership
Leadership

Did you unzip that file?
You need to point to the metadat.zip file

$esx = Get-VMHost -Name $EsxName

Install-VMHostPatch -VMHost $esx -HostPath '/vmfs/volumes/xxxxxxx/metadata.zip'

Restart-VMHost -VMHost $esx -Confirm:$false


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

Reply
0 Kudos