将多个结果分隔到不同的行
Separating multiple results onto different lines
我有以下 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 和 Deny 都显示混合到同一输出中的多个结果。
即使我将最后一行更改为:
$results | sort name | Out-GridView
这也显示了相同的 5 个对象 Identity、User、AccessRights、IsInherited 和 Deny 全部聚集在一起。
我正在寻找的是将 5 个对象分开 Identity、User、AccessRights、IsInherited 和 Deny 到不同的行,对于其余对象,只需重复例如名称、UPN、许可证、收件人类型详细信息、TotalItemSize、Alias、IsLicensed 和 ItemCount 将在每个旁边重复导致 5 个对象 Identity、User、AccessRights、IsInherited 和 拒绝.
这样我可以对输出做更多的事情,例如将其放入 Excel 并修改结果。
我会使用如下单独定义的音符属性来构建您的输出结果,它对我有用,并且可以从这里轻松导出为您需要的任何格式。检查我是否以正确的顺序获得了所有属性。
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
}
我有以下 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 和 Deny 都显示混合到同一输出中的多个结果。
即使我将最后一行更改为:
$results | sort name | Out-GridView
这也显示了相同的 5 个对象 Identity、User、AccessRights、IsInherited 和 Deny 全部聚集在一起。
我正在寻找的是将 5 个对象分开 Identity、User、AccessRights、IsInherited 和 Deny 到不同的行,对于其余对象,只需重复例如名称、UPN、许可证、收件人类型详细信息、TotalItemSize、Alias、IsLicensed 和 ItemCount 将在每个旁边重复导致 5 个对象 Identity、User、AccessRights、IsInherited 和 拒绝.
这样我可以对输出做更多的事情,例如将其放入 Excel 并修改结果。
我会使用如下单独定义的音符属性来构建您的输出结果,它对我有用,并且可以从这里轻松导出为您需要的任何格式。检查我是否以正确的顺序获得了所有属性。
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
}