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