header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Unable to b
Last Post 29 Dec 2009 01:46 AM by James. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
JamesUser is Offline
Basic Member
Basic Member
Posts:374
Avatar

--
24 Dec 2009 03:50 AM
    Hello,

    I am getting the following error:

    New-Mailbox : Cannot bind argument to parameter 'UserPrincipalName' because it is null.

    My CSV is populated and the names are correct I have used the same code and the same CSV file over and over again. The only thing to change here was the CSV file name however its not playing. I have no idea why.

    Does anyone know why?

    My code is as follows:



    Code Start

    Import-Csv -Path "C:\AVA.csv" | ForEach-Object { #Set your variables from the object in the pipeline. #Each row of the CSV file will create one object. #The column headers will be the property names for that #object. $Server = $_.ExchangeServer $StorageGroup = $_.StorageGroup $MailboxDatabase = $_.MailboxDatabase $FirstName = $_.FirstName $LastName = $_.Surname $DisplayName = $_.ActualDisplayName $School = $_.School $PrincipalName = $_.ConcatEmailAddress $Name = $FirstName.Trim() + $LastName.Trim() $Alias = $FirstName.Trim() + $LastName.Trim() $OU = "stockport.sch.uk/schools/" + $School + "/Users" $Database = $Server + "\" + $StorageGroup + "\" + $MailboxDatabase $secureString = ConvertTo-SecureString "password" -AsPlainText –Force # create new mailboxes Write-host "Creating Mailbox..." New-Mailbox -DisplayName $DisplayName -Password $secureString -Alias $Alias -FirstName $FirstName -LastName $LastName -Name $Name -OrganizationalUnit $OU -UserPrincipalName $PrincipalName -Database $Database #Get the maibox we need to modify $mailbox = Get-Mailbox -Identity $Alias $newaddress = $_.SecondaryEmailAddress #$newaddress1 = $_.AdditionalEMailAddress $mailbox.EmailAddresses += $newaddress #$mailbox.EmailAddresses += $newaddress1 Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false }

    Code End

    Any help is much appreciated

    James
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1642
    Avatar

    --
    24 Dec 2009 05:03 AM
    Do a "write-host $variable" before using and/or defining each variable to see if is actually empty.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:332
    Avatar

    --
    25 Dec 2009 09:06 AM
    Well the error is occurring on UserPrincipalName. That parameter is getting its data from $PrincipalName which is getting its data from $_.ConcatEmailAddress. Make sure that you are referencing the proper column in your csv file. Is ConcatEmailAddress the correct spelling (double check there isn't a spelling discrepancy). Are there spaces in that heading; if so you will need to put quotes around the name of the field i.e $_."Concat Emaill Address" for it to pull information from that field.

    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    29 Dec 2009 01:46 AM
    Hello,

    I copied and pasted the names from the script into the csv and tested and everything is working fine. I could not see however the problem but its now working fine.

    Many Thanks for your replies.

    Much Appreciated.

    James
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer