Automation

 View Only
  • 1.  Remove-DataStore issue

    Posted Feb 07, 2012 10:22 PM

    $datastores = get-datastore | >{$_.parentfolder.name -eq "deletethese"}

    $vmhost = get-vmhost 'fqdn'

    $datastores | %{remove-datastore -datastore $_ -vmhost $vmhost}

    this will delete the first, then when it gets to the second it crashes saying there are resources in use... i rerun the whole thing (grab DS and try to remove) and it deletes the one it just had a problem with and then throws a problem with the next one...

    I have to remove about 25 datastores that i'd prefer not to do by hand, whats going on here?



  • 2.  RE: Remove-DataStore issue

    Posted Feb 08, 2012 05:11 AM

    Hello, jrich523-

    Hm, I was not able to reproduce the "crashes" that you talk about.  I wonder, what version of PowerCLI are you using?  You can get that info by running:

    PS C:\> Get-PowerCLIVersion

    How does the Remove-Datastore do if you pass the array of datastores ("$datastores") directly to it, instead of one datastore at a time in a Foreach-Object loop?  So, the last line would be like (with the confirmation suppression added):

    Remove-Datastore -Datastore $datastores -VMHost $vmhost -Confirm:$false

    (since, per the docs, the cmdlet accepts an array of datastore objects -- you do not have to pass them in one at a time)

    And, I assume that the ">" in the first line is just a type, and that it is really a "%" in your code -- is that true?



  • 3.  RE: Remove-DataStore issue

    Posted Feb 08, 2012 01:06 PM

    PowerCLI Version

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

    VMware vSphere PowerCLI 4.1 build 264274

    This  version does not support an array

    how ever i think i found the problem. If i monitor the vcenter console i see that it does a recan VMFS on all hosts (san disk) and i've put a sleep in at the end of the command (allowing the scan to complete) and it seems to be working. here is the final command.

    $datastores | %{write-host "Removing $($_.name)";Remove-Datastore -Datastore $_ -VMHost $hosts[0] -Confirm:$false; sleep 5}

    $datastores = Get-Datastore | ?{$_.parentfolder.name -eq "datastore"}

    This time i was able to get many more out but not all. this is fine because it will only take a few runs to get them all.

    Thanks

    Justin



  • 4.  RE: Remove-DataStore issue

    Posted Feb 08, 2012 01:36 PM

    Time was needed between removes for the recan of VMFS that was automatically kicked off upon removal