Automation

 View Only
  • 1.  Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )

    Posted Jan 15, 2019 12:41 PM

    Hi Friends

    Looking for a script to delete folders with its contents from a Datastore , I tried to do it with below Managed object  , but not able to find a method that can be used for deleting a folder

    Appreciate if anyone can help with it

    SearchDatastoreSubFolders_Task(searchSubFolders)

    Thanks

    Jooshil



  • 2.  RE: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )
    Best Answer

    Posted Jan 15, 2019 01:05 PM

    You need the FileManager for that.

    Try like this, it will delete the folder and all its content.

    $file = '[MyDS] TestFolder'

    $dcName = 'MyDC'


    $dc = Get-Datacenter -Name $dcName

    $si = Get-View ServiceInstance

    $fileMgr = Get-View -Id $si.Content.FileManager

    $fileMgr.DeleteDatastoreFile($file, $dc.ExtensionData.MoRef)



  • 3.  RE: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )

    Posted Jan 16, 2019 06:48 AM

    Thanks Luc

    That works :smileyhappy:



  • 4.  RE: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )

    Posted Jan 22, 2019 08:37 PM

    HI LUC,

                        is there any script to Delete the Empty folders in Data stores.



  • 5.  RE: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )

    Posted Jan 22, 2019 08:51 PM

    This will also delete an empty folder.



  • 6.  RE: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )

    Posted Jan 22, 2019 09:05 PM

    Great, please need a script to delete the ONLY empty folders in Datastore. we don't want touch any other folders.