Mooser Less能帮我再看看jltx200684提出的关于Foreach-object问题吗?有新的问题。谢谢!


PowerShell交流中心分类: 变量-函数-脚本-条件-循环-参数Mooser Less能帮我再看看jltx200684提出的关于Foreach-object问题吗?有新的问题。谢谢!
0
jltx200684 asked 9年 ago
Mooser Lee 管理员 replied 9年 ago

hello,你能把比较完整的代码贴出来吗?

Mooser Lee 管理员 replied 9年 ago

可以编辑问题,把你的代码放在pre标签中。

jltx200684 replied 9年 ago

是7天前你回答的那个,谢谢!

jltx200684 replied 9年 ago

我编辑不了,点编辑没有反应啊<br>Get-DistributionGroupMember -Identity “_systemintegration_DEPT” | <br>foreach-object {<br> if($_.smaccountname) { <br> get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize<br> } <br> else{<br> Write-Warning ("smaccountname 为空在"+ $_)<br> } <br>这是7天前你帮忙的。但还有报错。

jltx200684 replied 9年 ago

你好,谢谢帮助。但我执行后会有以下报错,但成功的数据也有。我就不能确定是否是全部数据。所以我加 > file.csv 想导出来却不能执行。管道未执行,因为已有管道正在执行。不能并行执行管道。 + CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed

jltx200684 replied 9年 ago

上面是我执行后的报错。

Mooser Lee 管理员 replied 9年 ago

$failedItems=@()Get-DistributionGroupMember -Identity “_systemintegration_DEPT” | foreach-object { if($_.smaccountname) { get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize } else{ Write-Warning (“smaccountname 为空在”+ $_) $failedItems += $_ } }

1 Answers
0
Mooser Lee 管理员 answered 9年 ago
$failedItems=@()
Get-DistributionGroupMember -Identity “_systemintegration_DEPT” |
foreach-object {
 if($_.smaccountname) {  
   get-mailboxstatistics -identity $_.smaccountname | select displayname,totalitemsize
   }
 else{
 Write-Warning ("smaccountname 为空在"+ $_)
  $failedItems += $_
   }  
 }
Mooser Lee 管理员 replied 9年 ago

在管道后面使用ConvertTo-Csv | Out-File my.csv

Mooser Lee 管理员 replied 9年 ago

不要使用cmd中的 >

jltx200684 replied 9年 ago

我再试一下,先谢谢了。能解释一下新的命令吗?因为我初学powershell,并且没有一点编程经验。如果可以的话能推荐一本书,对我这样的初学者试用的。

Mooser Lee 管理员 replied 9年 ago

新命名为ConvertTo-Csv 将对象转化成文本字符串。Out-File将文本字符串输出为文件。

Mooser Lee 管理员 replied 9年 ago

PowerShell 在线教程:http://www.pstips.net/powershell-online-tutorials/PowerShell电子书:http://www.pstips.net/cat/ebook/

jltx200684 replied 9年 ago

你好,我又试了一次但还是有下面错误,不过有数据输出的。但对比了一下这个分发组成员少40人左右。管道未执行,因为已有管道正在执行。不能并行执行管道。 + CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed

jltx200684 replied 9年 ago

下面是我从网上找到的之前提问题时描述过。请看看。1.他是这样做的get-distributiongroupmember -identity tss(组名) |select samaccountname >c:\tss.csv2.再对这个输出文本编辑,“删除空格”、将Samaccountname 缩短成一个比较简单的参数,变成identity3.Import-Csv c:\tss.csv |ForEach-Object{Get-Mailboxstatistics -identity $_.identity |select displayname,Itemcount,totalitemsize} >c:\Usersize.csv如果我按照这样的操作,导数的分发组成员数是对的230多,用你的方法只能导出197人,他说他也没有这个能力进行一次命令出来。