【问题标题】:Separating multiple results onto different lines将多个结果分离到不同的行
【发布时间】: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 个对象 IdentityUserAccessRightsIsInherited拒绝全部显示混合到同一输出中的多个结果。

即使我把最后一行改成这样:

$results | sort name | Out-GridView

这也显示了相同的 5 个对象 IdentityUserAccessRightsIsInheritedDeny 全部聚集在一起。

我正在寻找的是分离 5 个对象 IdentityUserAccessRightsIsInherited拒绝到不同的行,其余的对象,只是重复例如名称UPN许可证RecipientTypeDetailsTotalItemSize别名、IsLicensedItemCount 将在 5 个对象 IdentityUser、AccessRightsIsInheritedDeny

这样我可以对输出做更多的事情,例如把它放到 Excel 中并处理结果。

【问题讨论】:

    标签: powershell powershell-2.0 powershell-3.0 office365


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-31
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多