try{ if(Get-ADuser -Filter {SamAccountName -eq "john.doe"}) {Write-Warning "A person with username << john.doe >> already exists on the domain! A new account has not been created."} else {New-ADUser -SamAccountName "john.doe" -UserPrincipalName "john.doe@contoso.com" -AccountPassword (ConvertTo-SecureString -AsPlainText "password" -Force) -Enabled $true -Path 'OU=Users,DC=contoso,DC=com'}} catch{Write-Warning "Failed to create user: $($error[0])"};