大家好:
Get-DistributionGroupMember -Identity “_systemintegration_DEPT” | select samaccountname | foreach-object {get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize} 为什么会有如下出错
无法将参数绑定到参数“Identity”,因为该参数是空值。
+ CategoryInfo : InvalidData: (:) [Get-MailboxStatistics], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxStatistics
如果分两步做,使用第一个管道导出为CSV文件,再通过import-csv就不会报错。
小弟是刚接触powershell也没学过编程,请大家帮助一下,能否说的详细点。先谢谢了!
你的完整调用为:
Get-DistributionGroupMember -Identity “_systemintegration_DEPT” |
select samaccountname |
foreach-object {
get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize
}
提示:无法将参数绑定到参数“Identity”,因为该参数是空值。说明返回的部分元素中的samaccountname为空。
你的第二个管道是多余的:可以直接删掉
改成这样应当不会出问题:
Get-DistributionGroupMember -Identity “_systemintegration_DEPT” |
foreach-object {
if($_.smaccountname) {
get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize
}
else{
Write-Warning ("smaccountname 为空在"+ $_)
}
}
你好,谢谢帮助。但我执行后会有以下报错,但成功的数据也有。我就不能确定是否是全部数据。所以我加 > file.csv 想导出来却不能执行。<br>管道未执行,因为已有管道正在执行。不能并行执行管道。 + CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed
Mosser Lee请再看看我出现的新问题。谢谢!
你可以这样吧失败的数据保存起来:
$failedItems=@()
Get-DistributionGroupMember -Identity “_systemintegration_DEPT” |
foreach-object {
if($_.smaccountname) {
get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize
}
else{
Write-Warning ("smaccountname 为空在"+ $_)
$failedItems += $_
}
}
$failedItems.count