Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument errors with office 365 cmdlet

I'm having issues feeding variables into the New-MsolUser cmdlet. I'm getting the following error.

New-MsolUser : A positional parameter cannot be found that accepts argument 'â?UserPrincipalName [email protected] â?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 am using 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 the details..

like image 500
barconr Avatar asked Jun 23 '14 16:06

barconr


1 Answers

–UserPrincipalName and –UsageLocation use not the minus character but the character with code 8211. Maybe it's fine but try to use the standard minus instead, just to be sure.

like image 115
Roman Kuzmin Avatar answered Nov 04 '22 00:11

Roman Kuzmin