我有以下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个对象身份,用户, AccessRights , IsInherited 和 Deny 都显示混合到同一输出中的多个结果。
即使我将最后一行改为:
$results | sort name | Out-GridView
这也显示了相同的5个对象身份,用户, AccessRights , IsInherited 和拒绝所有人聚在一起
我要找的是分开5个对象身份,用户, AccessRights , IsInherited 和拒绝到不同的线上,对于其他对象,只需重复例如名称, UPN ,许可, RecipientTypeDetails , TotalItemSize , Alias < / strong>, IsLicensed 和 ItemCount 会在5个对象身份,用户,< strong> AccessRights , IsInherited 和拒绝。
这样我可以用输出做更多的事情,例如把它放到Excel中并按下结果。
答案 0 :(得分:1)
我会使用像下面单独定义的注释属性来构建输出结果,它适用于我,可以轻松地从此处导出到您需要的格式。检查我是否按顺序获得了所有属性。
foreach($user in $mailboxusers)
{
$UPN = $user.userprincipalname
$match = New-Object -TypeName PSObject
$match | Add-Member -Type NoteProperty -Name "Name" -Value $user.name
$match | Add-Member -Type NoteProperty -Name "UPN" -Value $UPN
$match | Add-Member -Type NoteProperty -Name "Alias" -Value $user.alias
$match | Add-Member -Type NoteProperty -Name "RecipientTypeDetails" -Value $user.RecipientTypeDetails
$match | Add-Member -Type NoteProperty -Name "Identity" -Value ($Permissions | where {$_.Identity -eq ($user).DisplayName}).Identity
$match | Add-Member -Type NoteProperty -Name "User" -Value ($Permissions | where {$_.Identity -eq ($user).DisplayName}).User
$match | Add-Member -Type NoteProperty -Name "AccessRights" -Value ($Permissions | where {$_.Identity -eq ($user).DisplayName}).AccessRights
$match | Add-Member -Type NoteProperty -Name "IsInherited" -Value ($Permissions | where {$_.Identity -eq ($user).DisplayName}).IsInherited
$match | Add-Member -Type NoteProperty -Name "Deny" -Value ($Permissions | where {$_.Identity -eq ($user).DisplayName}).Deny
$match | Add-Member -Type NoteProperty -Name "IsLicensed" -Value ($Licenses | where {$_.UserPrincipalName -eq ($user).UserPrincipalName}).IsLicensed
$match | Add-Member -Type NoteProperty -Name "TotalItemSize" -Value ($Statistics | where {$_.DisplayName -eq ($user).DisplayName}).TotalItemSize
$match | Add-Member -Type NoteProperty -Name "ItemCount" -Value ($Statistics | where {$_.DisplayName -eq ($user).DisplayName}).ItemCount
$match | Add-Member -Type NoteProperty -Name "License" -Value ($Licenses | where {$_.UserPrincipalName -eq ($user).UserPrincipalName}).Licenses.AccountSkuId
$Results += $match
}