【发布时间】:2014-08-13 18:28:39
【问题描述】:
我在将变量输入到 New-MsolUser cmdlet 时遇到问题。我收到以下错误。
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
我使用的代码是:
$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"
当我对详细信息进行硬编码时,此命令有效..
【问题讨论】:
-
看起来它被
$TargetFullname中的值阻塞了。您是在使用给定的值(“新用户”)还是其他? -
上面的代码是我正在测试并得到上述错误的值。
-
如果将
[string]::Concat($TargetFname ," ", $TargetLname)括在括号中,是否还会出现错误? -
–UserPrincipalName和–UsageLocation不使用 minus 字符,而是使用代码为 8211 的字符。也许没问题,但请尝试使用标准减号,以确保. -
@RomanKuzmin 将您的评论转换为
right答案!
标签: powershell office365