Remove a VMFS datastore using powershell
2017-11-21 14:08
309 查看
Recently I had to remove a lot of VMFS datastores from our VMWare infrastructure as we had migrated to new storage and no longer needed them.
In order to remove a datastore from your vmware infrastructure correctly you must follow the instructions given in this article. http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004605
Basically it says you have to make sure nothing is using the datastore and then unmount and detach the datastore from each connected host. Since we work with large clusters with many ESXi hosts I didn’t enjoy the prospect of manually unmounting and detaching each datastore from each host. To avoid this I found this article http://blogs.vmware.com/vsphere/2012/01/automating-datastore-storage-device-detachment-in-vsphere-5.html which explains how to automate datastore removal. It’s a great article and includes a few functions which give you the ability to unmount and detach datastores like described above. I simply used these functions to create the script in this blog.
2. The datastore is unmounted on each host connected to it.
3. The datastore is detached on each host connected to it.
4. At the end of the script run the datastore name and LUN canonical name is returned. This is useful as you will probably need this information when you have to delete the LUN in your storage system later on.
II.Copy the script to your computer and open it with and editor like powershell_ISE or powerGUI.
III. In the #Parameters section enter the name of your vCenter server and the name of the datastore you wish to remove.
IV. Hit F5 to run the script.
Forward from
https://scriptingblog.com/2014/08/13/remove-a-vmfs-datastore-using-powershell/
In order to remove a datastore from your vmware infrastructure correctly you must follow the instructions given in this article. http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004605
Basically it says you have to make sure nothing is using the datastore and then unmount and detach the datastore from each connected host. Since we work with large clusters with many ESXi hosts I didn’t enjoy the prospect of manually unmounting and detaching each datastore from each host. To avoid this I found this article http://blogs.vmware.com/vsphere/2012/01/automating-datastore-storage-device-detachment-in-vsphere-5.html which explains how to automate datastore removal. It’s a great article and includes a few functions which give you the ability to unmount and detach datastores like described above. I simply used these functions to create the script in this blog.
If the functions are already there then why use this script?
I wrote this script so that it does everything for you in one go. You don’t have to mess around with the functions or cmd-lets yourself. Also, I made a few changes to the mentioned functions which I feel improve them. Basically all you have to do is put in the name of the datastore and run the script.What does the script do exactly?
1. The script gets the datastore info and then asks for confirmation before beginning the removal process.2. The datastore is unmounted on each host connected to it.
3. The datastore is detached on each host connected to it.
4. At the end of the script run the datastore name and LUN canonical name is returned. This is useful as you will probably need this information when you have to delete the LUN in your storage system later on.
How do I run the script?
I. Go through the checklist “Unmounting a LUN checklist” here http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004605 and make sure your datastore is ready for removal.II.Copy the script to your computer and open it with and editor like powershell_ISE or powerGUI.
III. In the #Parameters section enter the name of your vCenter server and the name of the datastore you wish to remove.
IV. Hit F5 to run the script.
The script itself
I’m not going to go into details about the code as you can see all that in the links to KB articles above. I have simply copied in the script for you here. Please leave a comment if you find the script useful. Enjoy!Forward from
https://scriptingblog.com/2014/08/13/remove-a-vmfs-datastore-using-powershell/
相关文章推荐
- ext store remove old datas load new datas优化
- Store binary data to MySQL using escape_string in MySQLdb
- Using Oracle Berkeley DB as a NoSQL Data Store
- Cross datastore persistence using Kundera
- 调用对象 “ha-datastoresystem”的“HostDatastoreSystem.QueryVmfsDatastoreCreateOptions” 失败。
- remove a datastore from vCenter Server Inventory
- How to Properly Remove Datastore or LUN from ESXi 5.x hosts
- How to Deploy or Remove a Solution Package Using PowerShell Commands
- How to Properly Remove Datastore or LUN from ESXi 5.x hosts
- “HostDatastoreSystem.QueryVmfsDatastore- CreateOptions”
- Create DataStore using FDO API in Map 3D
- Using PowerCLI to get a Datastore from an NAA ID
- How To Generate An XML File As A Target Datastore Using ODI In An Integration Interface ? [ID 454268
- Store User and Application Data in the Correct Location
- Android训练课程(Android Training) - 使用Volley传输网络数据(Transmitting Network Data Using Volley)
- Using jQuery with Client-Side Data Binding
- extjs 之Ext.data.Store[Grid]操作 【增删修改】
- Ext.data.Store
- csharp:SQLite and Access using C# code read data
- Ext.data.Store