I am trying to script new user creation process on windows servers and one part of this script is to set SPN records for that particular user. But I keep getting error "New-ADUser: The name reference is invalid" when I try to put the SPN parameter with values. I am trying to follow an example from Microsoft website (Link) Any help will be appreciated.
It works fine if I remove ServicePrincipalNames parameter itself.
Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell
Import-Module ActiveDirectory
$properties=@{
Name="SQL Service Account For $customerName"
DisplayName= "SQL Service Account For $customerName"
ServicePrincipalNames= @{Add="MSSQLSvc\'$dbServerName.$domainName':1433","MSSQLSvc\'$dbServerName':1433"}
Description= "SQL Service Account For $customerName"
UserPrincipalName= "$sqlUser@$domainName"
GivenName= "SQL Service Account For"
Surname= "$customerName"
SamAccountName= $sqlUser
AccountPassword= $pwdsql
Path= $path
LogonWorkstations= $dbServerName
TrustedForDelegation= $true
Enabled= $True
Credential= $credential
PasswordNeverExpires= $True
CannotChangePassword= $True
}
New-ADUser @properties
Thanks,
Rahul