2015-02-24 45 views
0

我有以下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個對象身份用戶AccessRightsIsInherited拒絕都示出混合到相同的輸出多個結果。

即使我最後一行改成這樣:

$results | sort name | Out-GridView 

這也顯示了相同的5個對象身份用戶AccessRightsIsInherited拒絕都聚集在一起。

我所尋找的是分離的5個對象身份用戶AccessRightsIsInherited拒絕到不同的線路,併爲其餘對象,只是重複例如名稱UPN許可將RecipientTypeDetailsTotalItemSize別名IsLicensedItemCount中將每個結果旁邊被重複在5個對象身份用戶AccessRightsIsInherited and Deny

這樣我可以做更多的事情與輸出,把它放入Excel例如,並按摩結果。

回答

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 
}