【发布时间】:2015-04-25 15:28:47
【问题描述】:
我有以下 PowerShell 脚本,我可以在其中运行以从 Office 365 获取良好的混合报告。
$Results = @()
$MailboxUsers = get-mailbox -resultsize unlimited
$Statistics = $MailboxUsers | Get-MailboxStatistics | select *
$Licenses = Get-MsolUser | select *
$Permissions = $MailboxUsers | Get-MailboxPermission | select *
foreach($user in $mailboxusers)
{
$UPN = $user.userprincipalname
$Properties = @{
Name = $user.name
UPN = $UPN
Alias = $user.alias
RecipientTypeDetails = $user.RecipientTypeDetails
Identity = ($Permissions | where {$_.Identity -eq ($user).DisplayName}).Identity
User = ($Permissions | where {$_.Identity -eq ($user).DisplayName}).User
AccessRights = ($Permissions | where {$_.Identity -eq ($user).DisplayName}).AccessRights
IsInherited = ($Permissions | where {$_.Identity -eq ($user).DisplayName}).IsInherited
Deny = ($Permissions | where {$_.Identity -eq ($user).DisplayName}).Deny
IsLicensed = ($Licenses | where {$_.UserPrincipalName -eq ($user).UserPrincipalName}).IsLicensed
TotalItemSize = ($Statistics | where {$_.DisplayName -eq ($user).DisplayName}).TotalItemSize
ItemCount = ($Statistics | where {$_.DisplayName -eq ($user).DisplayName}).ItemCount
License = ($Licenses | where {$_.UserPrincipalName -eq ($user).UserPrincipalName}).Licenses.AccountSkuId
}
$Results += New-Object psobject -Property $properties
}
$results | sort name | fl
但是,当我运行它时,有 5 个对象 Identity、User、AccessRights、IsInherited 和 拒绝全部显示混合到同一输出中的多个结果。
即使我把最后一行改成这样:
$results | sort name | Out-GridView
这也显示了相同的 5 个对象 Identity、User、AccessRights、IsInherited 和 Deny 全部聚集在一起。
我正在寻找的是分离 5 个对象 Identity、User、AccessRights、IsInherited 和拒绝到不同的行,其余的对象,只是重复例如名称、UPN、许可证、RecipientTypeDetails、TotalItemSize、别名、IsLicensed 和 ItemCount 将在 5 个对象 Identity、User、AccessRights、IsInherited 和 Deny。
这样我可以对输出做更多的事情,例如把它放到 Excel 中并处理结果。
【问题讨论】:
标签: powershell powershell-2.0 powershell-3.0 office365