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.
source share