How can we find out Orphaned VMDK files in all the Data-stores.
Amazing coincidence, I'm about to modify the script for the EXACT same reason.
As I am still learning here,
Would it look something like this?
foreach($folder in $searchResult | Where {$folder.FolderPath -ne ".snapshot/*"})
I am guessing not I still them LOL
I don't have access to my lab right now, but I would suggest a match operator.
Something like: foreach($folder in ($searchResult | Where {$folder.FolderPath -notmatch "snapshot"})
But be aware that this might cause skipped folders if you have some that have 'snapshot' in their name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc.
Tried that Still getting snapshot folders.
Tried
foreach($folder in $searchResult | Where {$folder.FolderPath -notmatch "snapshot"})
foreach($folder in $searchResult | Where {$folder.FolderPath -notlike "*snapshot*"})
Extents | : [DS] .snapshot/daily.2017-10-24_2100/<ServerName>/<ServerName>-flat.vmdk |
Name | : <ServerName>.vmdk |
Thin | : True |
CapacityKB : 52428800
Folder | : [DS] .snapshot/daily.2017-10-24_2100/<ServerName>/ |
Size | : 18209038336 |
I'll have to check in my lab.
Hold on
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried this:
foreach($folder in ($searchResult | Where {$folder.FolderPath -notmatch "*.snapshot*"})){
As the snapshot folder is actually called .snapshot. But received a lot of errors:
At line:77 char:52
+ ... $searchResult | Where {$folder.FolderPath -notmatch "*.snapshot*"})){
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
parsing "*.snapshot*" - Quantifier {x,y} following nothing.
At line:77 char:52
+ ... $searchResult | Where {$folder.FolderPath -notmatch "*.snapshot*"})){
The dot and the asterisk are special characters in RegEx expressions.
And the (not)match operator expects a valid RegEx expression.
Try with the -notlike instead of -notmatch
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I had tried the -notlike and was receiving the same output as I posted before.
I tried
foreach($folder in $searchResult | Where {$folder.FolderPath -notlike "*snapshot*"})
I have even tried
foreach($folder in $searchResult | Where {$folder.FolderPath -notlike ".snapshot*"})
Oh, also tried with the () in it like
foreach($folder in ($searchResult | Where {$folder.FolderPath -notlike "*.snapshot*"}))
Yeah this is my exact line 77
foreach($folder in ($searchResult | Where {$folder.FolderPath -notlike "*.snapshot*"})){
Still getting them listed.
Hey LucD have you had a chance to check this out in your lab? Thanks!
My flight landed 3 hours ago, but I had a quick check in my lab.
With the following, I don't see any of the .snapshot folders popping up in the result
foreach($folder in ($searchResult | where{$_.FolderPath -notmatch "\] \.snapshot/"})){
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That did it LucD !!! Thank you so much for the help. Can you give a brief explanation as to why that worked and what I was doing wrong previously?
We're taking all the results (in $searchResult) and we 'pipe' them through a Where-clause.
An object in the pipeline is addressed by the $_ variable, not the $folder variable.
That's also why I explicitly used the parenthesis, to show what order everything is done.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect thank you!
Hey LucD do you have any advice in changing the script to run against a datastore cluster?
This should work
Get-DatastoreCluster -Name MyDSC | Get-Datastore | Remove-OrphanedData
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That mostly worked. I say mostly because I don't think there is an error in the code but rather in my vCenter. It worked perfectly fine for one DS cluster but not for another. I got this error:
Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "An error occurred while communicating with the remote host."
At C:\Users\mhenze_sa\Documents\Scripts\Delete Orphan VMDKs.ps1:76 char:9
+ $searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Is perhaps one of the ESXi nodes in a cluster that is linked to the DSC powered off?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
One is in maintenance mode. I thought that would have been okay but maybe that's where the error lies.