Hi Powershell users.
I have a script that creates users from a csv file. I also want the script to create a new-mailbox for these users in the csv file.
But im getting this error:
Value cannot be null.
Parameter name: serverSettings
+ CategoryInfo : NotSpecified: (
[Enable-Mailbox], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.Exchange.Management.RecipientTasks.EnableMailbox
+ PSComputerName : VMSRVMail2
$mail = New-PSSession -ComputerName VMSRVMail2
$users = import-csv 'C:\Script\users.csv' -Delimiter ';'
Foreach ($user in $users) {
New-ADUser -Name ($user.fornavn + " " + $user.efternavn) -DisplayName ($user.fornavn + " " + $user.efternavn) -Title $user.titel -Description $user.beskrivelse -GivenName $user.fornavn -SurName $user.efternavn -SamAccountName $user.samnavn -UserPrincipalName $user.upn -Path $user.'path,,,' -ScriptPath "logon.bat" -HomeDrive "U:" -HomeDirectory "\\vmsrv2\CitrixData$\brugerbib\$sam" -AccountPassword (convertto-securestring $user.password -AsPlainText -Force) -ChangePasswordAtLogon:$True -Enabled:$True
$sam = $user.samnavn
$alias = $user.samnavn
Invoke-Command -Session $mail -ScriptBlock {
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
Enable-Mailbox -Identity $Using:alias
}
}
I have also tried with this line: Enable-Mailbox -Identity âtest.local/Brugerâ -Alias $_.alias -Database âMBX1â
Which is giving me:
Cannot validate argument on parameter âAliasâ. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
+ CategoryInfo : InvalidData: (
[Enable-Mailbox], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Exchange.Management.RecipientTasks.EnableMailbox
+ PSComputerName : VMSRVMail2