By the way, this is the preferred way to prompt for input if a parameter hasn’t been passed in to your script. When you mark everything as Mandatory, the PowerShell engine takes care of that for you (including masking password input). It’s probably still using Read-Host or something similar to that under the hood, but you don’t need to know that. More importantly, this gives you the ability to run the script without all the prompts, if you want. (eg, .\NewADUser.ps1 ‘Bob Jones’ Bob Jones bjones ‘OU=Users,DC=Contoso,DC=com’ (‘p@ssw0rd’ | ConvertTo-SecureString -AsPlainText -Force) )
param ( [Parameter(Mandatory = $true)] [string] $Name, [Parameter(Mandatory = $true)] [string] $GivenName, [Parameter(Mandatory = $true)] [string] $Surname, [Parameter(Mandatory = $true)] [string] $SamAccountName, [Parameter(Mandatory = $true)] [string] $Path, [Parameter(Mandatory = $true)] [System.Security.Securestring] $AccountPassword ) New-ADUser @PSBoundParameters -Enabled $true -AccountExpirationDate $null