Waqkas,
Sure, the command to remove a local user would be:
Remove-LocalUser -Name <user name goes here> -Verbose
Take a look at the following for a more detailed script:
Function Remove-LocalUser
{
<#
.Synopsis
This function deletes a local user
.Description
This function deletes a local user
.Example
Remove-LocalUser -userName "adam"
Removes a new local user named adam.
.Parameter ComputerName
The name of the computer upon which to delete the user
.Parameter UserName
The name of the user to delete
#>
[CmdletBinding()]
Param(
[Parameter(Position=0,
Mandatory=$True,
ValueFromPipeline=$True)]
[string]$userName
)
$computerName = $env:ComputerName
$User = [ADSI]"WinNT://$computerName"
$user.Delete('user',$userName)
} #end function Remove-LocalUser
$localUsers = Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'" | Select-Object Name
foreach ($localUser in $localUsers.Name){
Write-Host $localUser
Remove-LocalUser -userName $localUser
}
See how that works.
Cheers,
Adam