VMware Cloud Community
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

Get-ChildItem with filter inside ESXi Host's Datastore

Hi

so im trying to get file via filter from within a datastore path folder

and a bit straggling to do so

im thinking to do it with get-childitem

and this is what i last used:

$vibPath = "/vmfs/volumes/$($ds)/$($vibFolderName)/vib20/esx-nsxv/"
$vilFilePath = (Get-ChildItem -Filter '*.vib' $vibPath)

but it just saying that C:\vmfs\volumes etc does not exists

how can I direct it into the DS and not to search in windows where the script is running form?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect you are mixing two things here.
With Get-ChildItem you wanted to get a list of the VIBs on that datastore.
Use the VimDatastore provider for that.

Then you use esxcli to install a VIB, where you have to provide a viburl.
There you will have to provide that path to the VIB as a path in the root filesystem of the ESXi node.

You can combine those in 1 script.
Note that the selection of the specific VIB I leave to you. You might have to add additional condition to that Where-clause.

$dsName = "MyDS"
$vibPath = 'vxlan/vib20/esx-nsxv'
$vibName = 'xyz.vib'

$ds = Get-Datastore -Name $dsName
New-PSDrive -Name DS -Root \ -PSProvider VimDatastore -Datastore $ds | Out-Null
$vib = Get-ChildItem -Path "DS:/$vibPath" -Filter *.vib | where{$_.Name -eq $vibName} 
Remove-PSDrive -Name DS -Confirm:$false

$ds = Get-Datastore -Name $dsName
$dsPath = $ds.ExtensionData.Info.Url.Replace('ds://','')

$vibPath = $dsPath + $vib.DatastoreFullPath.Split(' ')[1]

$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.software.vib.install.CreateArgs()
$esxcli.software.vib.install.Invoke(@{viburl = $vibPath; dryrun = $true; vibname = $vibName})




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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

That filesystem (/vmfs/volumes) is not known.
So it goes and tries in the drive where you are currently located.

To access files on a Datastore you can use the VimDatastore provider.
Something like this for example

$dsName = "MyDS"
$ds = Get-Datastore -Name $dsName
New-PSDrive -Name DS -Root \ -PSProvider VimDatastore -Datastore $ds | Out-Null
Get-ChildItem -Path DS:


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

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

excellent!

only when I'm trying to use it, it looks like there is a space between the paths

Message: EsxCLI.CLIFault.summary;
InnerText:  [VibDownloadError] ('/vmfs/volumes/DS/ vxlan/vib20/esx-nsxv/*.vib', '', "unknown url type: '/vmfs/volumes/DS/ 

I assume because it looks like this:

[DS] vxlan/vib20/esx-nsxv/*.vib

and there an obvious space between the DS and the next folder 'vxlan'

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You should use it as a path with a drive letter

Get-ChildItem -Path DS:/vxlan


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

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

I did do that.

did with full path too, and it still the same

Get-ChildItem -Path DS:/vxlan/vib20/esx-nsxv/

and yet the error still

Message: EsxCLI.CLIFault.summary;
InnerText:  [VibDownloadError] ('/vmfs/volumes/DS/ vxlan/vib20/esx-nsxv/*.vib', '', "unknown url type: '/vmfs/volumes/DS/ 
vxlan/vib20/esx-nsxv/*.vib'")
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you using that path in an esxcli command?
That will not work, esxcli has no notion of the VimDatastore provider


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

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

that is correct,

I'm trying eventually install the vib

and I need the path of that vib for installation

how else could I get the path for it?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect you are mixing two things here.
With Get-ChildItem you wanted to get a list of the VIBs on that datastore.
Use the VimDatastore provider for that.

Then you use esxcli to install a VIB, where you have to provide a viburl.
There you will have to provide that path to the VIB as a path in the root filesystem of the ESXi node.

You can combine those in 1 script.
Note that the selection of the specific VIB I leave to you. You might have to add additional condition to that Where-clause.

$dsName = "MyDS"
$vibPath = 'vxlan/vib20/esx-nsxv'
$vibName = 'xyz.vib'

$ds = Get-Datastore -Name $dsName
New-PSDrive -Name DS -Root \ -PSProvider VimDatastore -Datastore $ds | Out-Null
$vib = Get-ChildItem -Path "DS:/$vibPath" -Filter *.vib | where{$_.Name -eq $vibName} 
Remove-PSDrive -Name DS -Confirm:$false

$ds = Get-Datastore -Name $dsName
$dsPath = $ds.ExtensionData.Info.Url.Replace('ds://','')

$vibPath = $dsPath + $vib.DatastoreFullPath.Split(' ')[1]

$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.software.vib.install.CreateArgs()
$esxcli.software.vib.install.Invoke(@{viburl = $vibPath; dryrun = $true; vibname = $vibName})




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

Reply
0 Kudos