0

在此处输入代码查找我的脚本以及我在某些 get-distribution group 属性上收到的错误消息。

属性是:managedby memberjoinrestriction memberdepartrestriction requiresenderauthenticationenabled

当我排除上述属性时,脚本会很好地返回而不会出错。

帮助我了解我在哪里做错了。

脚本:该脚本应该为通讯组批量导出信息

$Groups = Get-DistributionGroup –ResultSize Unlimited
$Groups | ForEach-Object {
$group = $_.Name
$primarySMTPAddress = $_.PrimarySMTPAddress
$managedby = $._ManagedBy 
$memberjoinrestriction = $._MemberJoinRestriction
$memberdepartrestriction = $._MemberDepartRestriction
$requiresenderauthenticationenabled = $._RequireSenderAuthenticationEnabled

Get-DistributionGroupMember $group | ForEach-Object {
New-Object -TypeName PSObject -Property @{
Group = $group
GroupPrimarySMTPAddress = $primarySMTPAddress
Member = $_.Name
ManagedBy = $managedby
MemberJoinRestriction = $memberjoinrestriction
MemberDepartRestriction = $memberdepartrestriction
RequireSenderAuthenticationEnabled = $requiresenderauthenticationenabled
EmailAddress = $_.PrimarySMTPAddress
}}} | Export-CSV "C:\DistributionGroupinfov1.csv" -NoTypeInformation -Encoding UTF8```

The error message is
```$._ManagedBy : The term '$._ManagedBy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:5 char:14
+ $managedby = $._ManagedBy
+              ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($._ManagedBy:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

$._MemberJoinRestriction : The term '$._MemberJoinRestriction' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:6 char:26
+ $memberjoinrestriction = $._MemberJoinRestriction
+                          ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($._MemberJoinRestriction:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

$._MemberDepartRestriction : The term '$._MemberDepartRestriction' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:7 char:28
+ $memberdepartrestriction = $._MemberDepartRestriction
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($._MemberDepartRestriction:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

$._RequireSenderAuthenticationEnabled : The term '$._RequireSenderAuthenticationEnabled' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:8 char:39
+ ... resenderauthenticationenabled = $._RequireSenderAuthenticationEnabled
+                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($._RequireSenderAuthenticationEnabled:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException```


When i run the command individually with a single attribute, it returns well without error
```Get-DistributionGroup -identity "support" | Format-table RequireSenderAuthenticationEnabled```
4

0 回答 0