When traversing a datastore in powershell, the default behavior of other providers doesn't seem to match the VimDatastore provider.
What I suspect is that .ToString() isn't returning a full path. A kin to [string](Get-Item C:\temp\file.txt) should return C:\temp\file.txt but if you do something like [string](Get-Item vmstores:\vCenter@443\) you get vCenter as well as [string](Get-Item vmstores:\ returns vmstores.
Example code:
function Get-NextItem ($Path) {
$CurrentItem = Get-Item -Path "$Path\$($_.Name)"
$ChildItems = Get-ChildItem -Path $Path | Where-Object {$_.PSIsContainer -eq $true}
If ($CurrentItem.PSIsContainer -eq $true) {
$ChildItems | ForEach-Object {
#Get-NextLevel $_ # This is how it should work...
Get-NextItem "$Path\$($_.Name)" # Ugly hack to it to work...
}
}
}
$drive = Get-PSDrive -PSProvider VimDatastore -Name vmstores
$vmstore = "$($drive):\"
Get-NextItem $vmstore
When traversing a datastore in powershell, the default behavior of other providers doesn't seem to match the VimDatastore provider.
What I suspect is that .ToString() isn't returning a full path. A kin to
[string](Get-Item C:\temp\file.txt)
should returnC:\temp\file.txt
but if you do something like[string](Get-Item vmstores:\vCenter@443\)
you getvCenter
as well as[string](Get-Item vmstores:\
returnsvmstores
.Example code: