I need to list ALL files that are in a datastore folder, including any files that start with a period such as the ".done" in the examples below. As you can see from an ssh session a simple "ls -al" will do the trick. In powershell the equivalent of "ls" is Get-ChildItem, but for some reason the Get-ChildItem cdmlet will not list anything that starts with a period, even when I use the -Force parameter. Using -LiteralPath does not work either. Any ideas?
EXAMPLE of listing the contents of the target direction looks like from an ssh session.
===========================================================
/vmfs/volumes/5356d508-51e862e7-6944-002590d8d27a/clone/pmlab-vm01-2015-05-19-18-00-02UTC # ls -al
drwxr-xr-x 1 root root 980 May 19 18:33 .
drwxr-xr-x 1 root root 560 May 19 18:33 ..
-rw-r--r-- 1 root root 0 May 19 18:33 .done
-rw------- 1 root root 32212254720 May 19 18:33 pmlab-vm01-flat.vmdk
-rw------- 1 root root 555 May 19 18:33 pmlab-vm01.vmdk
-rwxr-xr-x 1 root root 2903 May 19 18:20 pmlab-vm01.vmx
-rw-r--r-- 1 root root 268 May 19 18:20 pmlab-vm01.vmxf
/vmfs/volumes/5356d508-51e862e7-6944-002590d8d27a/clone/pmlab-vm01-2015-05-19-18-00-02UTC #
===========================================================
EXAMPLE of what the Get-ChildItem cdmlet returns
===========================================================
PS C:\Users\cdw_hms\Documents> Get-ChildItem -path $Target.PSPath -Force
Datastore path: [pmlab-v-hv01-disk1] clone/pmlab-vm01-2015-05-19-18-00-02UTC
LastWriteTime Type Length Name
------------- ---- ------ ----
5/19/2015 1:20 PM VmConfigFile 2903 pmlab-vm01.vmx
5/19/2015 1:33 PM VmDiskFile 555 pmlab-vm01.vmdk
5/19/2015 1:20 PM File 268 pmlab-vm01.vmxf
5/19/2015 1:33 PM File 32212254720 pmlab-vm01-fla...
PS C:\Users\cdw_hms\Documents> get-childitem -LiteralPath 'VMware.VimAutomation.Core\VimDatastore::\LastConnectedVCenterServer\pmlab\pmlab-v-hv01-disk1\clone\pmlab-vm01-2015-05-19-18-00-02UTC\'
Datastore path: [pmlab-v-hv01-disk1] clone/pmlab-vm01-2015-05-19-18-00-02UTC
LastWriteTime Type Length Name
------------- ---- ------ ----
5/19/2015 1:20 PM VmConfigFile 2903 pmlab-vm01.vmx
5/19/2015 1:33 PM VmDiskFile 555 pmlab-vm01.vmdk
5/19/2015 1:20 PM File 268 pmlab-vm01.vmxf
5/19/2015 1:33 PM File 32212254720 pmlab-vm01-fla...
===========================================================
I've ruled out that the issue has anything to do with the file size being zero bytes by creating a temp file that is zero bytes that does not start with a period. Get-ChildItem lists the temp file with no problem. The issue is definitely with the period.
I'm afraid there is no way to display files starting with a dot this way.
In fact it is not a VimDatastore provider issue as far as I can tell, but it seems to be the way the HostDatastoreBrowser is implemented.
The following script for example will not show a file that starts with a dot.
$dsName = 'MyDatastore'
$ds = Get-Datastore -Name $dsName
$dsBrowser = Get-View $ds.ExtensionData.browser
$flags = New-Object VMware.Vim.FileQueryFlags
$flags.FileSize = $true
$flags.FileType = $true
$flags.FileOwner = $true
$flags.Modification = $true
$query = New-Object VMware.Vim.FileQuery
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec.details = $flags
$searchSpec.Query += $query
$searchSpec.sortFoldersFirst = $true
$searchSpec.SearchCaseInsensitive = $true
$searchSpec.MatchPattern = '*'
$rootPath = "[" + $ds.Name + "]"
$result = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
foreach($folder in $result){
"$($folder.FolderPath)"
foreach($file in $folder.File){
"`t$($file.Path)"
}
}
The only way, that I know of, to see such files is from the console.
So I'm afraid you will have to revert to something like plink.exe to solve this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for looking into that for me.
What about using get-esxcli? I was playing around with that yesterday. From an ssh session to a host, I've always used the linux command to list directory contents (ls -al), but I was hopeful that there might be a esxcli command that does the same. Alas, I came up short. Do you know of any equivalent esxcli command to "ls -a?"
I'm afraid esxcli doesn't offer such a feature.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That settles it then. Thanks for the quick replies and for the help!