-
1. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 6, 2019 3:01 AM (in response to DashrathReddy)Try like this, but be warned that the VimDatastore provider is not very fast.
Get-ChildItem -Path vmstore: |Select -first 1 |
ForEach-Object -Process {
Get-ChildItem -Path "vmstore:/$($_.Name)" -Recurse |
where{-not $_.PSIsContainer} |
select FullName,LastWriteTime,Length
}
-
2. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
DashrathReddy Feb 6, 2019 4:20 AM (in response to LucD)I got into the below error.. Basically I am looking for the data which can tell me how long the files are not been accessed or used in datastores. (storage cleanup activity), please suggest if you have other-ways to accomplish.
Error received:
Get-ChildItem : An error occurred while communicating with the remote host.
At line:3 char:4
+ Get-ChildItem -Path "vmstore:/$($_.Name)" -Recurse |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], HostCommunication
+ FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.HostCommunication,Microsoft.PowerShell.Commands.GetChildItemCommand
-
3. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 6, 2019 4:29 AM (in response to DashrathReddy)Could it be that you have no permission to access specific parts of your environment?
What PowerCLI version are you using? -
4. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
DashrathReddy Feb 6, 2019 7:49 PM (in response to LucD)Hi... I am using "administrator@vsphere.local" credentials and seems I have all the required credentials. Please find the PSVersion details below.
Name Value
---- -----
PSVersion 5.1.17134.407
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.407
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
-
5. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 6, 2019 11:57 PM (in response to DashrathReddy)I mean the PowerCLI version, not the PowerShell version.
-
6. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
DashrathReddy Feb 7, 2019 2:42 AM (in response to LucD)Please find the PowerCli version below..
PowerCLI Version
----------------
VMware PowerCLI 11.0.0 build 10380590
-
7. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 7, 2019 2:55 AM (in response to DashrathReddy)Can you check with the following?
Does it also produce that error?Get-ChildItem -Path vmstore: |ForEach-Object -Process {
Get-ChildItem -Path "vmstore:/$($_.Name)"
}
If that works, can you try this one.
Get-ChildItem -Path vmstore: |ForEach-Object -Process {
Get-ChildItem -Path "vmstore:/$($_.Name)" |
ForEach-Object -Process {
Get-ChildItem -Path $_.DatastoreBrowserPath | select FullName
}
}
-
8. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
DashrathReddy Feb 7, 2019 3:36 AM (in response to LucD)Hi.. It is working but I could not get LastWriteTime & Length information in it. Attached the screen shot for reference. please assist.
-
powercli output.jpg 137.2 K
-
-
9. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 7, 2019 3:39 AM (in response to DashrathReddy)Can you try the 1st script I gave you again?
-
10. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
DashrathReddy Feb 7, 2019 4:34 AM (in response to LucD)Hi.. I received the same error by using the first script.
Seems I do not have access on some files inside the folders (as we are using "Recurse" parameter and it tries to get information on file level) it is trying to get those details and failing. I tried to get LastWriteTime & Length at folder level and got the attached results (lengh information is missing for folders and files like .iso/.txt turned with the size details). Attached the screen shot for reference.
Get-ChildItem -Path vmstore: |
ForEach-Object -Process {
Get-ChildItem -Path "vmstore:/$($_.Name)" |
ForEach-Object -Process {
Get-ChildItem -Path $_.DatastoreBrowserPath | select FullName,LastWriteTime,Length
}
}
-
powercli output1.jpg 124.9 K
-
-
11. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 7, 2019 4:43 AM (in response to DashrathReddy)That's what I already suspected earlier.
The problem is that you only get the 1st level this way.With -Recurse you will stumble on the error.
Give it a try like thisGet-ChildItem -Path vmstore: |ForEach-Object -Process {
Get-ChildItem -Path "vmstore:/$($_.Name)" -Recurse -ErrorAction SilentlyContinue |
Select FullName, LastWriteTime, Length
}
-
12. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
DashrathReddy Feb 7, 2019 6:23 AM (in response to LucD)No Luck... I did a try, but same error...
PS C:\> Get-ChildItem -Path vmstore: |
>> ForEach-Object -Process {
>>
>> Get-ChildItem -Path "vmstore:/$($_.Name)" -Recurse -ErrorAction SilentlyContinue |
>>
>> Select FullName, LastWriteTime, Length
>>
>> }
Get-ChildItem : An error occurred while communicating with the remote host.
At line:4 char:4
+ Get-ChildItem -Path "vmstore:/$($_.Name)" -Recurse -ErrorAction Si ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], HostCommunication
+ FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.HostCommunication,Microsoft.PowerShell.Commands.GetChildItemCommand
-
13. Re: PowerCLi Script to fetch file details like FullName, LastWriteTime, Length stored on the datastores
LucD Feb 7, 2019 6:42 AM (in response to DashrathReddy)Then I'm afraid I have no other solution at hand.
You will have to solve the connection issue before you can get a full file list.As an alternative, you only get the list for a specific datastore or specific datastores.