0
1
Here is my basic user account creation script. I would like to use Runas to have it run New-Aduser as a domain account. Ideally I would add an input prompt for the account. Any advice? I haven't been able to get it to work. The script does work fine when I remote into another machine with an administrative account and run it.
#credentials
?
#Input Prompts
$Firstname = Read-Host 'What is users first name?'
$Lastname = Read-Host 'What is users last name?'
$UserID = Read-Host 'What is users ID?'
#Static Variables
$Password = (ConvertTo-SecureString -AsPlainText 'PASSWORD' -Force)
$Displayname = "$lastname, $firstname BCA:EX"
$OUPath = 'OU=AAA Users,OU=AAA,OU=AAA,OU=AAA,OU=AAA,OU=AAA,DC=AAA,DC=AAA'
#used to add parameters
$Parameters = @{
'SamAccountName' = $UserID
'UserPrincipalName' = $UserID
'Name' = $Firstname
'GivenName' = $Firstname
'Surname' = $Lastname
'DisplayName' = “$Displayname”
'AccountPassword' = $password
'ChangePasswordAtLogon' = $true
'Enabled' = $true
'Path' = $OUPath
}
import-module activedirectory
New-ADUser @Parameters