|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Copyright Microsoft Corporation |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +<# |
| 16 | +.Synopsis |
| 17 | + Internal helper: projects a CrossTenantAccessPolicy API response into the flat |
| 18 | + parameter-aligned output shape shared by the *-DefaultEntraXTAP and |
| 19 | + *-PartnerEntraXTAP cmdlets. |
| 20 | +
|
| 21 | +.Description |
| 22 | + Decodes the nested TargetConfiguration model back into the flat property names |
| 23 | + that match the new cmdlet input parameters: |
| 24 | +
|
| 25 | + Default mode (IsPartner = $false): emits Id + flat properties. |
| 26 | + Partner mode (IsPartner = $true): emits PartnerTenantId + flat properties. |
| 27 | +
|
| 28 | + Output property mapping: |
| 29 | + M365CollaborationInbound.Users.accessType → M365CollaborationInbound ("Allowed"|"Blocked") |
| 30 | + M365CollaborationInbound.Users.targets[user] → M365CollaborationInboundTargetUsers |
| 31 | + M365CollaborationOutbound.UsersAndGroups.accessType → M365CollaborationOutbound ("Allowed"|"Blocked") |
| 32 | + M365CollaborationOutbound.UsersAndGroups.targets[user] → M365CollaborationOutboundTargetUsers |
| 33 | + M365CollaborationOutbound.UsersAndGroups.targets[group] → M365CollaborationOutboundTargetGroups |
| 34 | + AppServiceConnectInbound.Applications.accessType → AppServiceConnectInbound ("Allowed"|"Blocked") |
| 35 | + AppServiceConnectInbound.Applications.targets[application] → AppServiceConnectInboundTargetApplications |
| 36 | +#> |
| 37 | +function ConvertTo-EntraXTAPFlatOutput { |
| 38 | + param( |
| 39 | + [Parameter(Mandatory = $true)] |
| 40 | + $Result, |
| 41 | + |
| 42 | + [Parameter()] |
| 43 | + [switch] |
| 44 | + $IsPartner |
| 45 | + ) |
| 46 | + |
| 47 | + # Helper: capitalise first letter of accessType for enum output ("allowed" → "Allowed") |
| 48 | + function Format-AccessType { |
| 49 | + param([string]$Value) |
| 50 | + if ([string]::IsNullOrEmpty($Value)) { return $null } |
| 51 | + return [System.Globalization.CultureInfo]::InvariantCulture.TextInfo.ToTitleCase($Value.ToLower()) |
| 52 | + } |
| 53 | + |
| 54 | + # Helper: extract target IDs from a TargetConfiguration for a given targetType. |
| 55 | + function Get-TargetIds { |
| 56 | + param($Config, [string]$TargetType) |
| 57 | + if ($null -eq $Config -or $null -eq $Config.Targets) { return $null } |
| 58 | + $ids = @($Config.Targets | Where-Object { $_.TargetType -eq $TargetType } | ForEach-Object { $_.Target }) |
| 59 | + if ($ids.Count -eq 0) { return $null } |
| 60 | + return $ids |
| 61 | + } |
| 62 | + |
| 63 | + # ------------------------------------------------------------------ |
| 64 | + # M365CollaborationInbound → .Users (user targets only) |
| 65 | + # ------------------------------------------------------------------ |
| 66 | + $inboundConfig = if ($null -ne $Result.M365CollaborationInbound) { $Result.M365CollaborationInbound.Users } else { $null } |
| 67 | + $inboundAccessType = if ($null -ne $inboundConfig) { Format-AccessType $inboundConfig.AccessType } else { $null } |
| 68 | + $inboundUsers = if ($null -ne $inboundConfig) { Get-TargetIds -Config $inboundConfig -TargetType 'user' } else { $null } |
| 69 | + |
| 70 | + # ------------------------------------------------------------------ |
| 71 | + # M365CollaborationOutbound → .UsersAndGroups (user + group) |
| 72 | + # ------------------------------------------------------------------ |
| 73 | + $outboundConfig = if ($null -ne $Result.M365CollaborationOutbound) { $Result.M365CollaborationOutbound.UsersAndGroups } else { $null } |
| 74 | + $outboundAccessType = if ($null -ne $outboundConfig) { Format-AccessType $outboundConfig.AccessType } else { $null } |
| 75 | + $outboundUsers = if ($null -ne $outboundConfig) { Get-TargetIds -Config $outboundConfig -TargetType 'user' } else { $null } |
| 76 | + $outboundGroups = if ($null -ne $outboundConfig) { Get-TargetIds -Config $outboundConfig -TargetType 'group' } else { $null } |
| 77 | + |
| 78 | + # ------------------------------------------------------------------ |
| 79 | + # AppServiceConnectInbound → .Applications (application targets) |
| 80 | + # ------------------------------------------------------------------ |
| 81 | + $appConfig = if ($null -ne $Result.AppServiceConnectInbound) { $Result.AppServiceConnectInbound.Applications } else { $null } |
| 82 | + $appAccessType = if ($null -ne $appConfig) { Format-AccessType $appConfig.AccessType } else { $null } |
| 83 | + $appIds = if ($null -ne $appConfig) { Get-TargetIds -Config $appConfig -TargetType 'application' } else { $null } |
| 84 | + |
| 85 | + # ------------------------------------------------------------------ |
| 86 | + # Emit flat output — property names match cmdlet input parameters. |
| 87 | + # ------------------------------------------------------------------ |
| 88 | + if ($IsPartner) { |
| 89 | + [PSCustomObject]@{ |
| 90 | + PartnerTenantId = $Result.TenantId |
| 91 | + M365CollaborationInbound = $inboundAccessType |
| 92 | + M365CollaborationInboundTargetUsers = $inboundUsers |
| 93 | + M365CollaborationOutbound = $outboundAccessType |
| 94 | + M365CollaborationOutboundTargetUsers = $outboundUsers |
| 95 | + M365CollaborationOutboundTargetGroups = $outboundGroups |
| 96 | + AppServiceConnectInbound = $appAccessType |
| 97 | + AppServiceConnectInboundTargetApplications = $appIds |
| 98 | + } |
| 99 | + } else { |
| 100 | + [PSCustomObject]@{ |
| 101 | + Id = $Result.Id |
| 102 | + IsServiceDefault = $Result.IsServiceDefault |
| 103 | + M365CollaborationInbound = $inboundAccessType |
| 104 | + M365CollaborationInboundTargetUsers = $inboundUsers |
| 105 | + M365CollaborationOutbound = $outboundAccessType |
| 106 | + M365CollaborationOutboundTargetUsers = $outboundUsers |
| 107 | + M365CollaborationOutboundTargetGroups = $outboundGroups |
| 108 | + AppServiceConnectInbound = $appAccessType |
| 109 | + AppServiceConnectInboundTargetApplications = $appIds |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +<# |
| 115 | +.Synopsis |
| 116 | + Internal helper: projects a M365CapabilityBase API response into the flat |
| 117 | + parameter-aligned output shape shared by the *-DefaultM365XTAPCapability and |
| 118 | + *-PartnerM365XTAPCapability cmdlets. |
| 119 | +
|
| 120 | +.Description |
| 121 | + Decodes the nested M365CapabilityInboundAccess model back into the flat |
| 122 | + property names that match the cmdlet input parameters: |
| 123 | +
|
| 124 | + InboundAccess.IsAllowed → IsAllowed |
| 125 | + InboundAccess.ResourceScopes |
| 126 | + .Included[ResourceType=user] → IncludedUsers |
| 127 | + .Included[ResourceType=group] → IncludedGroups |
| 128 | + .Excluded[ResourceType=user] → ExcludedUsers |
| 129 | + .Excluded[ResourceType=group] → ExcludedGroups |
| 130 | +
|
| 131 | + Default mode (IsPartner = $false): |
| 132 | + Emits CapabilityId, LastModifiedDateTime, IsAllowed, Included/Excluded Users/Groups. |
| 133 | +
|
| 134 | + Partner mode (IsPartner = $true): |
| 135 | + Prepends PartnerTenantId before CapabilityId. |
| 136 | +#> |
| 137 | +function ConvertTo-EntraXTAPM365CapabilityFlatOutput { |
| 138 | + param( |
| 139 | + [Parameter(Mandatory = $true)] |
| 140 | + $Result, |
| 141 | + |
| 142 | + [Parameter()] |
| 143 | + [switch] |
| 144 | + $IsPartner |
| 145 | + ) |
| 146 | + |
| 147 | + # ------------------------------------------------------------------ |
| 148 | + # Helper: extract resource IDs from a scope array for a given type. |
| 149 | + # ------------------------------------------------------------------ |
| 150 | + function Get-ScopeIds { |
| 151 | + param($Scopes, [string]$ResourceType) |
| 152 | + if ($null -eq $Scopes) { return $null } |
| 153 | + $ids = @($Scopes | Where-Object { $_.ResourceType -eq $ResourceType } | ForEach-Object { $_.ResourceId }) |
| 154 | + if ($ids.Count -eq 0) { return $null } |
| 155 | + return $ids |
| 156 | + } |
| 157 | + |
| 158 | + $inbound = $Result.InboundAccess |
| 159 | + $isAllowed = if ($null -ne $inbound) { $inbound.IsAllowed } else { $null } |
| 160 | + $includedUsers = $null |
| 161 | + $includedGroups = $null |
| 162 | + $excludedUsers = $null |
| 163 | + $excludedGroups = $null |
| 164 | + |
| 165 | + if ($null -ne $inbound -and $null -ne $inbound.ResourceScopes) { |
| 166 | + $includedUsers = Get-ScopeIds -Scopes $inbound.ResourceScopes.Included -ResourceType 'user' |
| 167 | + $includedGroups = Get-ScopeIds -Scopes $inbound.ResourceScopes.Included -ResourceType 'group' |
| 168 | + $excludedUsers = Get-ScopeIds -Scopes $inbound.ResourceScopes.Excluded -ResourceType 'user' |
| 169 | + $excludedGroups = Get-ScopeIds -Scopes $inbound.ResourceScopes.Excluded -ResourceType 'group' |
| 170 | + } |
| 171 | + |
| 172 | + if ($IsPartner) { |
| 173 | + [PSCustomObject]@{ |
| 174 | + PartnerTenantId = $Result.AdditionalProperties['tenantId'] |
| 175 | + CapabilityId = $Result.Name |
| 176 | + LastModifiedDateTime = $Result.LastModifiedDateTime |
| 177 | + IsAllowed = $isAllowed |
| 178 | + IncludedUsers = $includedUsers |
| 179 | + IncludedGroups = $includedGroups |
| 180 | + ExcludedUsers = $excludedUsers |
| 181 | + ExcludedGroups = $excludedGroups |
| 182 | + } |
| 183 | + } else { |
| 184 | + [PSCustomObject]@{ |
| 185 | + CapabilityId = $Result.Name |
| 186 | + LastModifiedDateTime = $Result.LastModifiedDateTime |
| 187 | + IsAllowed = $isAllowed |
| 188 | + IncludedUsers = $includedUsers |
| 189 | + IncludedGroups = $includedGroups |
| 190 | + ExcludedUsers = $excludedUsers |
| 191 | + ExcludedGroups = $excludedGroups |
| 192 | + } |
| 193 | + } |
| 194 | +} |
| 195 | + |
0 commit comments