您的位置:首页 > 运维架构 > Shell

Exchange 2013 PowerShell遍历ForEach

2015-01-27 20:27 218 查看
ForEach语句是用于遍历访问一个集合中的值,我们先来看一个遍历收集邮箱的示例,只返回每个邮箱的名称:foreach($mailbox in Get-Mailbox) {$mailbox.Name}


此外,我们可以使用PowerShell管道结合使用ForEach管理和服务遍历处理对象,先来看一个示例Get-Mailbox | ForEach-Object {$_.Name}


当然了,之前我们提到过别名,这里也不例外Get-Mailbox | %{$_.Name}


再看看下面一个示例:Get-MailboxDatabase -Status | %{
$DBName = $_.Name
$whiteSpace = $_.AvailableNewMailboxSpace.ToMb()
"The $DBName database has $whiteSpace MB of total white space"
}


更多相关帮助命令:get-help about_for, get-help about_while, and get-help about_do
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息