下面是完整的問題,這是設定:
# Gets all room mailboxes
$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited
if ( !$places ){
$places = @()
# Gets Places for Room Mailboxes
foreach ( $room in $rooms ){
$places = Get-Place $room.PrimarySmtpAddress
}
}
$populatedTags = $places | Where-Object { $_.Tags -notlike $null }
$populatedTags | Select-Object Identity, Tags
Identity Tags
-------- ----
[email protected] {Microsoft Teams Room}
[email protected] {BYOD}
[email protected] {Microsoft Surface Hub}
[email protected] {Microsoft Teams Room, Microsoft Surface Hub, BYOD}
$populatedTags[3].Tags.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ArrayList System.Object
所以這是我用來獲取資料的代碼。我想要實作的是一個看起來像這樣的 CSV:
Identity,TAGS_Microsoft Teams Room,TAGS_BYOD,TAGS_Microsoft Surface Hub
Room1@example.com,TRUE,,
Room2@example.com,,TRUE,
Room3@example.com,,,TRUE
Room4@example.com,TRUE,TRUE,TRUE
我可以使用以下代碼將標簽添加為 NoteProperty:
$uniqueTags = $places | Select-Object Tags -Unique
$tags = $uniqueTags.Tags -join ","
$tagsArray = $tags.Split( "," )
$definitiveTags = $tagsArray | Select-Object -Unique
foreach ( $definitiveTag in $definitiveTags ){
if ( $definitiveTag -notlike $null ){
$places | Add-Member -MemberType NoteProperty -Name "TAGS_$definitiveTag" -Value $Null
}
}
現在我可以這樣做:
$places[0] | Select-Object Identity, TAGS_*
Identity : Room1@example.com
Microsoft Teams Room :
BYOD :
Microsoft Surface Hub :
有人對我如何填充這些欄位有任何想法嗎?我已經撓頭太久了。
uj5u.com熱心網友回復:
一種簡單的方法是計算所有標簽屬性的值,并將它們同時添加到每個地點物件中:
# Gets all room mailboxes
$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited
# Gets Places for Room Mailboxes
$places = foreach ( $room in $rooms ){ Get-Place $room.PrimarySmtpAddress }
# get the list of all used tags
$populatedTags = $places | Where-Object { $_.Tags -notlike $null }
$uniqueTags = $populatedTags | Select-Object Tags -Unique | Where Tags -NotLike $null
# iterate over places
$result = foreach ($place in $places) {
$entry = $place | select Identity #, other, properties, etc
# populate true/null values for each unique tag
foreach ($tagname in $uniqueTags) {
# calculate property value
$value = if ($place.tags -contains $tagname) {'TRUE'} else {$null}
# add property
$entry | Add-Member -MemberType NoteProperty -Name "TAGS_$tagname" -Value $value
}
# add to $result
Write-Output $entry
}
# view a table of places with any tag
$result |
# you cannot filter on a wildcard property, so have to awkwardly check like this
Where {($_.psobject.Properties|where Name -like 'TAGS_*').Value -like 'TRUE'} |
Select Identity,TAGS_*
這對于沒有太多資料且計算非常簡單的報告來說已經足夠了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/517246.html
標籤:电源外壳
