Argument Errors with Office 365 Cmdlet

I'm having problems loading variables into the New-MsolUser cmdlet. I get the following error.

New-MsolUser : A positional parameter cannot be found that accepts argument 'â?UserPrincipalName ausertest@test.ie â?UsageLocation'. At C:\users\test\Documents\test.ps1:148 char:1 + New-MsolUser -DisplayName $TargetFullname â?"UserPrincipalName $TargetEmail â?" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-MsolUser], ParentContainsErrorRecordException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Online.Administration.Automation.NewUser 

The code I use is:

 $Source = "AnotherADUser" $TargetFname = "New" $TargetLname = "User" $Target = "ausertest" $TargetFullname = [string]::Concat($TargetFname ," ", $TargetLname) $SourceEmail = (Get-ADUser $source -Property EmailAddress).EmailAddress $SourceDomain = $SourceEmail.split("@")[1] $TargetEmail = ([string]::Concat($Target , "@" , $SourceDomain)) New-MsolUser -DisplayName $TargetFullname –UserPrincipalName $TargetEmail –UsageLocation "IE" | Set-MsolUserLicense -AddLicenses "TESTINSTALL:EXCHANGESTANDARD" 

This command works when I hardcode details.

+6
source share
1 answer

–UserPrincipalName and –UsageLocation use the minus sign, but with code 8211. Maybe this is good, but try using the standard minus instead, to be sure.

+4
source

Source: https://habr.com/ru/post/971247/


All Articles