need assistance with a quest AD cmdlets script / O365

We have been using this script to add x500 entries to on-premise exchange accounts, and it works great. [Script is from Subsun]

$csv = import-csv c:\scripts\userlist.csv
 foreach ($line in $csv) 
    $user=Get-Mailbox -Identity $line.Username
     Set-Mailbox -Identity $line.Username -EmailAddresses $user.EmailAddresses 

Open in new window

how can we run this against the office 365 accounts?

I've tried running and get this error [after connecting to the cloud via posh]

Property 'EmailAddresses' cannot be found on this object; make sure it exists and is settable.
At C:\Users\myaccount\Desktop\add-X500Address-toProxyAddresses.ps1:5 char:12
+      $user. <<<< EmailAddresses+="X500:"+$line.legacyExchangeDN
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Mailbox
Who is Participating?
SubsunConnect With a Mentor Commented:
It should work with exchange online accounts as well..

Try to set it for single user and see if it works.. You may refer the following article for instructions...
siber1Author Commented:
hi Subsun, when I try to run that manually on one account I get the error:

Propary 'emailAddresses' cannot be found on this object, make sure that it exists and is settable.

I also get that error when I run your script against the csv.

thx - S.
Hmm.. What you get for..
Get-Mailbox subsun | Select EmailAddresses

Open in new window

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

siber1Author Commented:
that command works fine and lists the email addresses.

when I run your quest script against the input CSV here is the error:

Cannot process argument transformation on parameter 'Identity'. Cannot convert value "John Smith" to type "Microsoft
.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert hashtable to an object of the following type:
 Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter. Hashtable-to-Object conversion is not supported in restrict
ed language mode or a Data section."
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
Try changing line

Set-Mailbox -Identity $line.Username -EmailAddresses $user.EmailAddresses


Get-Mailbox $line.Username | Set-Mailbox -EmailAddresses $user.EmailAddresses
siber1Author Commented:
Hi Subsun,

slight correction, this is the code that I was using and it works for on premise, but not the cloud accounts:

Import-Csv Test.csv | % {
$user = Get-Mailbox $_.SMTP 
$user.emailAddresses += "X500:$($_.newsmtp)"
Set-Mailbox $user -emailAddresses $user.emailAddresses

Open in new window

input CSV column headers are: SMTP | newsmtp
siber1Author Commented:
thanks Subsun!
Sorry I was away, Is it working or are you still looking for assistance?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.