When I create my new users every week, I execute this powershell scripts I put together. It has been working like a charm for 10 months, but as of last week started throwing this strange error:
Invoke-Command : Cannot bind parameter 'Name' to the target. Exception setting "Name": "The property value is invalid.
The value can't contain leading or trailing whitespace."
At C:\Users\sarah.sanderson\AppData\Local\Temp\3\tmp_e30b6ca9-683a-430b-a22e-af2ff6d9ddc1_oam3omxv.1wu\tmp_e30b6ca9-683
a-430b-a22e-af2ff6d9ddc1_oam3omxv.1wu.psm1:27952 char:29
+ $scriptCmd = { & <<<< $script:InvokeCommand `
+ CategoryInfo : WriteError: (:) [New-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.NewMailbox
>
My script is as follows:
$cred = Get-Credential Contoso\
$session = New-PSSession -ConfigurationName Microsoft.Exchange - ConnectionUri http://Contoso-mbx/powershell -Credential $cred
Import-PSSession $session
Import-Module activedirectory
$Users = Import-Csv "C:\PSScripts\Create\users.csv" -header("lastname","firstame","program","password")
foreach ($User in $Users)
{
$OU = "OU=Users,DC=Contoso,DC=local"
$Password = $User.password
$Detailedname = $User.Lastname + "," + " " + $User.firstname
$UserFirstname = $User.Firstname
$UserLastname = $User.LastName
$SAM = $UserFirstname + "." + $UserLastname
New-Mailbox -UserPrincipalName $SAM@contoso.org -OrganizationalUnit $OU -Database "Mailbox Database 2" -Name $Detailedname -Password (ConvertTo-SecureString "Welcome1$" -AsPlainText -Force) -FirstName $UserFirstName -LastName $UserLastName -DisplayName $DetailedName -ResetPasswordOnNextLogon $true
}
According to the error, it has something to do with our exchange server, which is Server 2008 R2 running Exchange 2010, but there have been no changes made to it in the last 6 months. I can not figure out where I should even be looking to untangle this error. Any help would be greatly appreciated.
Snippet from lines 27950-58:
$clientSideParameters = Get-PSImplicitRemotingClientSideParameters $PSBoundParameters $True $scriptCmd = { & $script:InvokeCommand @clientSideParameters
-HideComputerName
-Session (Get-PSImplicitRemotingSession -CommandName 'New-Mailbox')-Arg ('New-Mailbox', $PSBoundParameters, $positionalArguments)
-Script { param($name, $boundParams, $unboundParams) & $name @boundParams @unboundParams }`