Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

argument transformation error

$
0
0

I am trying to write a script that will look at a group of users in Office 365 (this is for 10,000 existing users in on premise AD getting email in hybrid), test their E1 license status, and then create a remote mailbox for each user by passing the emailaddress object into a foreach loop.  I get the following error:

Cannot process argument transformation on parameter 'PrimarySmtpAddress'. Cannot convert null to type "Microsoft.Exchange.Data.SmtpAddress".
    + CategoryInfo          : InvalidData: (:) [Enable-RemoteMailbox], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Enable-RemoteMailbox
    + PSComputerName        : exch-cas.com

Here is the script:

$Groupname='Office365E1' 

 

 

$GroupID= (Get-MsolGroup-All|Where-Object {$_.DisplayName -eq$Groupname}).ObjectId

 

 

 

 

Write-Output"Checking for unlicensed users in group Office365E1 with ObjectGuid $GroupID... to enable remote mailbox"

$GroupMembers= (Get-MsolGroupMember-GroupObjectId$GroupID-All|Where-Object {$_.IsLicensed -eq"true"}).emailaddress

 

 

foreach ($Userin$GroupMembers) {

 

 

Try {

{

 

 

 

 

$ParsedUser=$User.Split("@")[0]}

 

 

 

 

Enable-RemoteMailbox$User-PrimarySmtpAddress$User-RemoteRoutingAddress$ParsedUser+'@tenant.mail.onmicrosoft.com'

 

 

Set-RemoteMailbox-Identity$User-EmailAddresses @{add=$ParsedUser+'@tenant.mail.onmicrosoft.com'}

 

 

 

 

Write-Output"Successfully enabled remotemailbox for $User"

}

 

catch {

 

 

 

 

Write-Warning"Error when enabling remotemailbox for $User"

}

}

I am very new to powerscript so detailed help would be appreciated so I know what I am doing wrong. Thanks.


Viewing all articles
Browse latest Browse all 6937

Trending Articles