top of page

PowerShell | Local Account Management

Delete Local Account

Delete.PNG

# Import List of Computers and Accounts
$MyData=Import-CSV C:\TEMP\Remove_LocalAccount.csv
# Loop through records
Foreach($Item in $MyData){  
# Command to delete local computer account
$MyCommand={Net USER $Args /Delete}  
# Executes command on machines from file
Invoke-Command $Item.Server -ScriptBlock $MyCommand -ArgumentList $Item.Account}    

Disable \ Enable Local Account

Delete.PNG

# Import List of Computers and Accounts
$MyData=Import-CSV C:\TEMP\LocalAccount.csv
# Command to Enable Local Computer Account
$MyCommand={

#If you want to Disable Change this to /active:no
Net User $Args /active:yes
Get-WMIObject Win32_UserAccount -Filter "Name='$Args'" | Select Caption, Disabled  
}

# Loop through records
Foreach($Item in $MyData){
# Executes command on machine from file
Invoke-Command $Item.Server -ScriptBlock $MyCommand -ArgumentList $Item.Account | Format-Table | Out-File C:\temp\MyFile.csv -Append
}

​

bottom of page