Powershell: Batch removing datastores from ESXi hosts (4.1)

27 Jun

We have to repurpose a bunch of 10 ESXi host for another purpose and I need to remove all the 12 datastores already mounted on the hosts. Here is a one-liner which I used to remove datastores quickly using vsphere powershell CLI commands. Note hosts.txt and ds.txt contains a list of hosts and datastores which you want to remove. Broke down into paragraphs for readability, this should be a one-liner. This is for 4.1 hosts. 5.0 host and beyond may require a different command due to storage I/O controls.

get-content c:\scripts\hosts.txt |

% { $h = $_ ; get-content c:\scripts\ds.txt |

%{ "Host="+$h+" : Removing Datastore... "+$_ ;

remove-datastore -Datastore $_ -VMhost $h -confirm:$false}}

Leave a comment

Posted by on June 27, 2013 in powershell, Scripts, vmware


Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: