Contributor
Contributor

Check for *.vib in a path

Jump to solution

Tried to list all upgrade files in a path

I store the actual update  vibs in a folder called Update. So I want to update the esxi with a script but Get-Childitem returns simply nothing.

$VMHost = "ESXi"
Connect-VIServer $VMHost
$esxcli = Get-ESXcli -VMHost $VMHost

$ds = Get-Datastore "STORE"
$Path = $ds.DatastoreBrowserPath + "\Update\"

$Files = Get-ChildItem -Recurse -Path $Path | sort

if ($Files.Count -gt 0) {

    Foreach ($File in $Files) {
        $esxcli.software.vib.install($File)
    }
}

How can I get the right path to update the esxi?

Thank you for any help

0 Kudos
1 Solution

Accepted Solutions
Leadership
Leadership

You could do something like this.
Remove the 'dryrun' property from the hash table, or set it to $false, when you are sure the script is working correctly.

$VMHost = "ESXi"
Connect-VIServer $VMHost
$esxcli = Get-ESXcli -VMHost $VMHost -V2

$ds = Get-Datastore "STORE"
$Path = $ds.DatastoreBrowserPath + "\Update\"

$Files = Get-ChildItem -Recurse -Path $Path | Sort-Object

if ($Files.Count -gt 0) {
    Foreach ($File in $Files) {
        $path = "$($ds.ExtensionData.Info.Url -replace 'ds://','')/$($File.DatastoreFullPath.Split(' ')[1])"
        $esxcli.software.vib.install.Invoke(@{viburl=$path;dryrun=$true})
    }
}

 


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

View solution in original post

0 Kudos
2 Replies
Leadership
Leadership

You could do something like this.
Remove the 'dryrun' property from the hash table, or set it to $false, when you are sure the script is working correctly.

$VMHost = "ESXi"
Connect-VIServer $VMHost
$esxcli = Get-ESXcli -VMHost $VMHost -V2

$ds = Get-Datastore "STORE"
$Path = $ds.DatastoreBrowserPath + "\Update\"

$Files = Get-ChildItem -Recurse -Path $Path | Sort-Object

if ($Files.Count -gt 0) {
    Foreach ($File in $Files) {
        $path = "$($ds.ExtensionData.Info.Url -replace 'ds://','')/$($File.DatastoreFullPath.Split(' ')[1])"
        $esxcli.software.vib.install.Invoke(@{viburl=$path;dryrun=$true})
    }
}

 


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

View solution in original post

0 Kudos
Contributor
Contributor

Thank you very much  for your reply. Solved.

0 Kudos