【问题标题】:FullyQualifiedErrorId : PositionalParameterNotFound,Add-DistributionGroupMemberFullyQualifiedErrorId : PositionalParameterNotFound,Add-DistributionGroupMember
【发布时间】:2020-06-06 00:28:02
【问题描述】:

我在 PowerShell 中为 O365 获得了这个小代码:

$dispname = Read-Host 'Displayname of room'
$alias = read-Host 'Alias of name (no spaces, no domain)'
$capacity = read-host 'Capacity of room'
$loc = read-host 'Location of room (site)'
$smtp = $alias + "@test.com"
$group = "cr." + $loc + ".all@test.com"

New-Mailbox -Name $alias -DisplayName $dispname -Room -office $loc

Set-Mailbox $alias -ResourceCapacity $capacity
Set-CalendarProcessing $alias -ScheduleOnlyDuringWorkHours $false -AutomateProcessing AutoAccept -AllowRecurringMeetings $True -AllowConflicts $False -ConflictPercentageAllowed 30 -MaximumConflictInstances 10 -BookingWindowInDays 365 -MaximumDurationInMinutes 1440
Set-MailboxCalendarConfiguration -identity $alias -WorkingHoursTimeZone "W. Europe Standard Time" -WorkingHoursStartTime 07:00:00 -WorkingHoursEndTime 18:00:00
Set-MailboxFolderPermission -Identity ${smtp}:\Calendar -User Default -AccessRights Reviewer

echo "Lokation is $loc"
echo "SMTP is $smtp"
echo "Gruppe is $group"

Add-DistributionGroupMember –Identity "$group" –Member "$smtp"

我很绝望,因为只有最后一行给我一个错误,我完全不知道为什么。

错误是:

找不到接受参数的位置参数 '房间名@test.com'。 CategoryInfo : InvalidArgument: (:) [Add-DistributionGroupMember], ParameterBindingException FullyQualifiedErrorId : PositionalParameterNotFound,Add-DistributionGroupMember PSComputerName:outlook.office365.com

因此变量$smtp 被正确设置为新资源的电子邮件地址以及组名称的变量$group,但不知何故它不适用于PowerShell。

问题是,当我手动执行所有步骤时,因此在 PowerShell 中将其逐行粘贴它可以正常工作。仅当我将其作为脚本运行时才出现错误。

【问题讨论】:

  • 您发布的代码无法运行,因为它都在带引号的字符串中。请修复它,以便显示的代码是您实际使用的代码。
  • 对不起,我遇到了一个错误,我必须标记代码,可能是太多了
  • 感谢您修复它! [grin] 我看到robdy 找到了问题并解决了问题。很高兴知道你让它根据需要工作。 ///// 这类东西的通常来源 [em/en-dash 而不是连字符;印刷引用而不是直接引用] 是从网页复制的。值得检查您复制和粘贴的所有内容
  • 另一个可能的故障来源是在参数值周围使用引号>>> –Identity "$group" –Member "$smtp" 咧嘴]

标签: powershell


【解决方案1】:

您粘贴的代码包含一个不是破折号的字符

Add-DistributionGroupMember –Identity "$group" –Member "$smtp"
                       here ^         and here ^

它的输出来自ASCII Value Tool:

Char    Dec Hex Oct
–       150 96  226

虽然应该是:

Char    Dec Hex Oct
-       45  2D  55

显然,在将其粘贴到 PowerShell 时,它会转换为 -,但在您运行脚本时不会发生这种情况。删除受影响的行,再次写入,应该可以正常工作了。

【讨论】:

  • 一千年后我都不会想到这一点……非常感谢,确实如此。难以置信:)
  • 不客气!确保mark the answer as accepted,以便其他人可以轻松找到它(因此我们都获得了一点声誉奖励)。
猜你喜欢
  • 2021-12-29
  • 2021-04-09
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 2012-08-21
  • 2013-07-17
  • 1970-01-01
相关资源
最近更新 更多