Automation

 View Only
  • 1.  How to find Orphaned VMDK files with -Delete Option

    Posted Mar 04, 2018 06:45 AM

    Hi LucD,

    After our discussion, I need to update the attached script that finds all the ESX Orphaned Files

    You wrote the script to find only the Orphaned Files within the Data-stores without deleting them

    Can you provide an updated Script that Find all the Orphaned Files and Give the user the -Delete Option ?

    Something like this : Orphaned files and folders - Spring cleaning - LucD notes

    Thanks in Advance



  • 2.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted Mar 04, 2018 09:16 AM

    Try with the attached new version.

    You can now do

    Get-Datastore -Name DS1 | Get-VmwOrphan -Delete -WhatIf

    Once you are sure the correct files will be removed, you can drop the WhatIf switch.

    I added an additional parameter ExcludeFolder, which is jandy if you to want speficic folders on the datastore (ISO folder, snapshot folder...)

    You can use it like

    Get-Datastore -Name DS1 | Get-VmwOrphan -ExcludeFolder 'Folder1','Folder2'

    And finally a PS, sometimes you will need to call the function at least twice.
    When an orphaned folder contains and orphaned file, the 1st run will remove the file, the 2nd run will remove the folder.



  • 3.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted Mar 04, 2018 09:36 AM

    Thank you a lot,

    I will check the script and update you with the results as soon as possible



  • 4.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted Oct 19, 2021 06:24 PM

    LucD,

    I read through the comments in your spring cleaning script. I admit it, I got lost when it came to altering the script for an NFS environment.

    Do you have a copy of your script that returns results for an NFS environment?

     



  • 5.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted Oct 19, 2021 07:19 PM

    It should be just changing

    if($ds.Type -eq "VMFS" -and $ds.ExtensionData.Summary.MultipleHostAccess){

    into

    if($ds.ExtensionData.Summary.MultipleHostAccess){
    


  • 6.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted 30 days ago

    Hi LucD,

    This script works great when using my admin account, but to be ultra cautious in production I want to do the first runs just for report generation using a read-only account, however when I run it I'm getting the following:

    Get-VmwOrphan -Datastore IOMEGA
    Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "Permission to perform this operation was denied."
    At C:\Users\dbutc\Dropbox\VMware\PowerCLI\orphaned_vmdks\get_orphaned_vmdks.ps1:76 char:9
    +         $searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPat ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException
     

    Could you explain what it's doing on this line which requires permissions higher than read-only? Hopefully I can just assign the minimum permissions required to run it.




  • 7.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted 30 days ago

    According to the SOAP API reference for the SearchDatastoreSubFolders method, it only requires the Datastore.Browse privilege.
    But it could be that calling the method from PS requires additional privileges.
    Did you check the vpxd log to see if the error there shows what is missing?



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 8.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted 26 days ago

    Good morning LucD,

    Here's a snippet from the vpxd.log just after I run the command:

    2024-11-10T02:00:57.804Z error vpxd[1722925] [Originator@6876 sub=Default opID=wcp-vCLS-99] [VpxLRO] -- ERROR lro-1717736 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:01:27.803Z error vpxd[1712578] [Originator@6876 sub=Default opID=wcp-vCLS-ee] [VpxLRO] -- ERROR lro-1717799 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:01:57.804Z error vpxd[1722925] [Originator@6876 sub=Default opID=wcp-vCLS-49] [VpxLRO] -- ERROR lro-1717847 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:02:27.805Z error vpxd[1722877] [Originator@6876 sub=Default opID=wcp-vCLS-ed] [VpxLRO] -- ERROR lro-1717907 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:02:57.804Z error vpxd[1712482] [Originator@6876 sub=Default opID=wcp-vCLS-73] [VpxLRO] -- ERROR lro-1717951 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:03:27.805Z error vpxd[1712792] [Originator@6876 sub=Default opID=wcp-vCLS-f9] [VpxLRO] -- ERROR lro-1718027 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:03:57.804Z error vpxd[1712578] [Originator@6876 sub=Default opID=wcp-vCLS-af] [VpxLRO] -- ERROR lro-1718073 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:04:27.803Z error vpxd[1722939] [Originator@6876 sub=Default opID=wcp-vCLS-e6] [VpxLRO] -- ERROR lro-1718108 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:04:57.803Z error vpxd[1722428] [Originator@6876 sub=Default opID=wcp-vCLS-d8] [VpxLRO] -- ERROR lro-1718157 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:04:58.685Z error vpxd[1722406] [Originator@6876 sub=Default opID=m2yw3io8-16ji-h5:70014514-f4fd-aa] [VpxLRO] -- ERROR lro-1718163 -- 52fbaa93-e9bc-860a-a2ba-51f6a9bbdcb8(5243903a-a66d-4b44-02b1-a1b74cd39943) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:05:27.804Z error vpxd[1722419] [Originator@6876 sub=Default opID=wcp-vCLS-77] [VpxLRO] -- ERROR lro-1718213 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:05:55.243Z error vpxd[1712865] [Originator@6876 sub=Authorize opID=bfaf2c8] Failed to cast authentication token helper
    2024-11-10T02:05:57.804Z error vpxd[1712443] [Originator@6876 sub=Default opID=wcp-vCLS-60] [VpxLRO] -- ERROR lro-1718262 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:06:27.804Z error vpxd[1722388] [Originator@6876 sub=Default opID=wcp-vCLS-58] [VpxLRO] -- ERROR lro-1718314 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:06:57.804Z error vpxd[1718309] [Originator@6876 sub=Default opID=wcp-vCLS-c1] [VpxLRO] -- ERROR lro-1718436 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:07:27.803Z error vpxd[1722864] [Originator@6876 sub=Default opID=wcp-vCLS-31] [VpxLRO] -- ERROR lro-1718516 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName
    2024-11-10T02:07:57.805Z error vpxd[1712489] [Originator@6876 sub=Default opID=wcp-vCLS-8d] [VpxLRO] -- ERROR lro-1718561 -- 52e49d5e-7ee1-bc3e-3f61-04d45dbfe09c(520ca728-5a95-5b30-8f60-40d6e141a559) -- VpxSettings -- vim.option.OptionManager.queryView: :vim.fault.InvalidName

    I'm thinking this could be the issue:



    2024-11-10T02:05:55.243Z error vpxd[1712865] [Originator@6876 sub=Authorize opID=bfaf2c8] Failed to cast authentication token helper

    Not finding much on google regarding this, I've tried searching the vpxd.log using the following:

    grep 'error' vpxd.log | more    (Result seen above)
    grep 'denied' vpxd.log | more  (no results)
    grep 'permission' vpxd.log | more   (no results)

    Is there anything else I can look for?









  • 9.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted 26 days ago

    You are correct. I was a little astonished to find out that the built in read-only account does not have Datastore.Browse privilege assigned, or any other privilege for that matter. After cloning the account, and granting only Datastore.Browse the script is running without error.

    Thanks!




  • 10.  RE: How to find Orphaned VMDK files with -Delete Option

    Posted 26 days ago

    Glad to hear you could fix the issue.



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------