PowerCLI script for deleting specified user account from ESX/ESXi hosts

vSphere PowerCLI: Windows PowerShell interface for managing vSphere is very powerful tool that can be used for managing large environments running ESX/ESXi servers.

I have tried writing a Powercli script for deleting specified user account from ESX host

This script reads the server names from servers.txt file and connects to each ESX server in txt file and removes the account mentioned in the script code, you can add additional commands to remove multiple users from a ESX/ESXi host.

Disadvantage of this script is that you need to enter root password every time it scans the each esx host in servers.txt file. Save this script as .ps1 file and enter the esx server names in servers.txt file

$hostx = get-content -path “c:\servers.txt”
foreach ($ESXhost in $hostx)
Connect-VIServer $ESXhost
Get-VMHostAccount -ID username | Remove-VMHostAccount -Confirm

Here “Username” is the user account to be deleted on the ESX servers mentioned in “Servers.txt” file


About asifkhandevadi

Hello, I have been working on windows since 9 years and currently working as windows, VMware and MS clustering SME at IBM. Whenever I get free time I participate in Microsoft forums and write some blogs to enhance my technical and communication skills through knowledge sharing. Please contact me on FB or Linkedin if you need any assistance on troubleshooting, implementation and virtualizaton.
This entry was posted in PowerCLI. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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