Hi Guys
PowerCLI rookie here, so sorry for stupid questions.
I’m trying to clean up a bunch of singehost with local datastores. So I need a script that can output a list of virtual machine files on a datastore that is not being used by VMs in the inventory. One of the problem is that the files on the datastore, is not all ways named exactly the same as the VM’s in the inventory.
Been looking at this, but I think the term “orphaned” is ‘sent what I think it is:
https://communities.vmware.com/thread/266913
Also there is this one, which I think I should be able to modify to do what I want:
Any hints or clues to push me in the right direction would be appreciated.
Hi LucD
i thought you ask to verify by " displaying the contents of $global:defaultviservers? "
That was the question mark for my question, no you shouldn't type the question mark, just $global:defaultviservers
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, going back to the error, you seem to be doing a Disconnect-VIServer from a server TestVC, which is not the name of your vCenter.
It looks as if the code you copied contains that TestVC somewhere in there.
Replace that with your own vCenter name.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
this is the screen shot , nothing came out ?
Then you probably have no orphaned VMs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi lucD
i seem, but when i use your script it show some of this file ( i filtered by vmx)
any different ?? just curios
without filters is as per attachment (sheet 1 is using your script, sheet 2 is using RV tools scan).
Can you attach (as files) both scripts you are using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What I meant was the code of both scripts, the one that doesn't return anything, and then the version of my code you are using.
That way I can compare which of the two might go wrong.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
here is the attachment.
from your script i copied and past into CLI, and then follow by command "Remove-OrphanedData -Datastore DS1" where DS1 i replace with my existing datastore one by one.
from another script i copied and past the "get-ProbablyOrphanedFile" , and then run this command "Get-Datastore | where {$_.name -like “SSD*”} | get-ProbablyOrphanedFile -matchpattern “*.vmx”| ogv" and follow by next script "DIsconnect-VIServer -Server “testVC” -confirm:$False" as per screen shot.
With the 2nd script you are using a Where-clause to only look at datastores whose name starts with SSD.
Do you actually have such datastores?
Try leaving out the Where-clause, and only select DS1, like
Get-Datastore -Name DS1 | Get-ProbablyOrphanedFile -matchpattern “*.vmx”|
Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
here is my datastore summary
and this is what i run just now
You have to dot-source that Get-ProbablyOrphanedFile function before calling it.
Otherwise you get exactly that error.
Store the code of the function in a .ps1 file, then dot-source the .ps1 file from the prompt (. .\thefile.ps1, and yes, there is a blank between the two dots)
After that you should be able to call the function from the prompt.
From your datastore list, it looks like you have no datastores whose name starts with SSD.
So that explains why nothing comes out of the call you made earlier.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry LucD
not sure which area went wrong ( I have test blank between two dot)
The function Get-FileInDatastireWithWorkflow is missing.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
how to fix this? where edit ?
help help
You'll find that missing function at the same location where you found the other function.
See Find orphaned vmdk files via workflow
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
i'm not good to modify the function, can help ? apologize
also can i modify SSD to non-SSD
Get-Datastore | where {$_.name -like “SSD*”} | get-ProbablyOrphanedFile -matchpattern “*.vmx”| ogv
Get-Datastore | where {$_.name -like “NON-SSD*”} | get-ProbablyOrphanedFile -matchpattern “*.vmx”| ogv
You will have to include all functions from that webpage in the .ps1 file that you dot-source.
The Where-clause you are using only looks at the name of the datastore, not the type of HW (SSD or non-SSD).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference