Saturday, August 25, 2012

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

No comments: