Hi I am working on a function that either deletes or disables a user in AD, by specifying either the Remove or disable parameter. If the parameters are set to true, the action should be performed. When I run my script it find the User and outputs it, when it comes to the disable block it prompts me for user Identity and disables the user when specifying it in the Command window.
I am new to PowerShell functions, can anyone tell me where am going wrong?
function Remove-User{
param(
[Parameter(Mandatory=$true)][string]$User,
[bool]$Remove,
[bool]$Disable
)
if (Get-ADUser -Filter {SamAccountName -eq $User})
{ Write-Output $User
if($Disable = $true){
Set-ADUser -SamAccountName $User -Enabled $false
}
elseif($Remove = $true){
Remove-ADUser -Identity $User
}
else{
Write-Output "Done"
}
}
else{
Write-Output "User doesn't exist"
}
}
Remove-User -User "TT" -Disable $true
