Automating the removal of ISCSI Datastores?


I am trying to automate the removal of datastores from multiple VMware hosts.  The current process is very tedious when you have multiple hosts.  The scenario is where I want to permanently remove the datastore from the host.  I have used the automation scripts from the following URL: and  This works great to unmount and detach the datastore.  What it doesn't do it to remove the static ISCSI target from the storage adapter, and then rescan.  I know it can be done programmatically, because I see Equallogic's VSM do it.  How can I do this as well?

What would be nice is to be able to pass the datastore name and the host's name to a script and have it complete all the tasks, rather than have it umount/detach from all hosts.

This would be very useful because we have 30 hosts (in 5 node clusters) and at least that many datastores.  We try to limit ISCSI connection count by exposing a single datastore to a single cluster.  Those VMs will run on that cluster.

Thanks for the help!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can reconfigure storage with host profiles. it will not cover host boot volume where network card emulates SCSI device from network iSCSI volume. You need to configure network card.
ddotsonAuthor Commented:
I'm not sure how a host-profile would come into play here.
Roshan MohammedCloud Engineering OfficerCommented:
you will have to run powercli commands such as;

Get-IScsiHbaTarget -Address x.x.x.x -Type Send | Remove-IScsiHbaTarget

detailed info on vmware kb arcticle,

where x.x.x.x is the ip address of the target.

this will need to be run against all the esxi hosts.

once it's done, run the scan hba option.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

host profile can define all your storeage mounts.
make host profile from one host and apply just storage part to all others
ddotsonAuthor Commented:
gheist-  Thanks for the idea, but with the fluid dynamics of our environment, I can see a problem with outdated host profiles.

S00007359, this will remove the Dynamic Discovery targets - such as my entire SAN array.  I want to remove the individual targets that point to each volume on my array.
Roshan MohammedCloud Engineering OfficerCommented:
i don't think so. if you have active iscsi datastores which are still used as datastores, it will continue to be present.

to be safe side, you can perform the following;

1) assume datastoreA that is a iscsi is no longer used as a datastore from any of the esxi hosts
2) from your san or iscsi server, un-present the datastoreA
3) Scan hba's

it will show as greyed out datastore

next, you can script to remove iscsi targets, Get-IScsiHbaTarget -Address x.x.x.x -Type Send | Remove-IScsiHbaTarget, and having conditions checks where the status is either not available, or offline.

this way, you are ensuring you are only removing/un-mounting the required data stores.
Once you enter maintenance mode no datastores are used and host profile applies cleanly...
ddotsonAuthor Commented:
The goal behind my question is to remove it from multiple hosts, but not all hosts.  For instance, if I want to move a datastore from Cluster A to Cluster B.  So once all of the VMs in the datastore have been moved to Cluster B, it's time to remove datastore access from Cluster A.
Roshan MohammedCloud Engineering OfficerCommented:
Yes that can be achieved, if you define your scope of hosts collection


$HostsList = Get-Cluster -name "A" | Get-Hosts
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.