Very simple powershell function (part below) . No matter what the $username variable is I always get the message 'User already exists'. Obviously I am trying with nonsense usernames that definitely don't exist as well as those that do. what's going on?
Function CreateStaff ()
# Check if an AD User of that name already exists
$ADUserCheck = get-aduser -Identity $username -ErrorAction SilentlyContinue
If ($ADUserCheck -eq $null)
Write-Host "User does not already exist, creating staff user..."
Write-Warning "$username already exists"