Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
Active Directory
Unable to b
Last Post 29 Dec 2009 01:46 AM by
James
. 3 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
James
Basic Member
Posts:374
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)
Veteran Member
Posts:1642
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
cameronove
Basic Member
Posts:332
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.
James
Basic Member
Posts:374
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.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
Active Directory
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2