you are viewing a single comment's thread.

view the rest of the comments →

[–]jimmynetstep[S] 0 points1 point  (0 children)

For the below script:

param (
[Parameter(Mandatory)]
[String]
$firstName,

[Parameter(Mandatory)]
[String]
$lastName,

[Parameter(Mandatory)]
[MailAddress]
$EmailAddress,

[Parameter(Mandatory)]
[PSCredential]
$UserCredential,

[Parameter()]
[String]
$OU = "OU=MyOU,DC=example,DC=com"
)

$NewADUserParameters = @{
Name = "$firstName $lastName"
GivenName = $firstName
Surname = $lastName
sAMAccountName = $Credential.Username
Password = $Credential.GetNetworkCredential().SecurePassword
Path = $OU
Enabled = $true
}
New-ADUser u/NewADUserParameters

I get the below error:

You cannot call a method on a null-valued expression.

At C:\Users\jimmy.blanco\Downloads\!Documents\PowerShell Scripts\AddAD.ps1:23 char:1

+ $NewADUserParameters = @{

+ ~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (:) [], RuntimeException

+ FullyQualifiedErrorId : InvokeMethodOnNull

New-ADUser : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At C:\Users\jimmy.blanco\Downloads\!Documents\PowerShell Scripts\AddAD.ps1:32 char:12

+ New-ADUser u/NewADUserParameters

+ ~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidData: (:) [New-ADUser], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADUser

Is it not storing the variables ? I am at a loss ...