Last active
September 30, 2025 17:54
-
-
Save joerodgers/b74e427abd855b0400af014d682dd9bd to your computer and use it in GitHub Desktop.
Reports the number of IP addresses consumed for each Power Platform environment that is associated with an enterprise policy. Remember to add 5 additional IP addresses to the total per unique subnet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Import-Module -Name "Microsoft.PowerPlatform.EnterprisePolicies" -ErrorAction Stop | |
| Import-Module -Name "Microsoft.PowerApps.Administration.PowerShell" -ErrorAction Stop | |
| # connect to az and power platform as user with the Power Platform Admin role | |
| Add-PowerAppsAccount -ErrorAction Stop | |
| Connect-AzAccount -ErrorAction Stop | Out-Null | |
| # get all environments with an enterprise policy applied | |
| $environments = Get-AdminPowerAppEnvironment | Where-Object -FilterScript { $_.Internal.properties.enterprisePolicies -ne $null } | |
| # enumerate matching environments and pull subet usage | |
| $environmentSubnetUsage = foreach( $environment in $environments ) | |
| { | |
| Write-Host "$(Get-Date) - Checking usage on env: ID:$($environment.EnvironmentName), Name:$($environment.DisplayName)" | |
| # redirect the information & host steams to NULL | |
| $environmentUsage = Get-EnvironmentUsage -EnvironmentId $environment.EnvironmentName -TenantId (Get-AzContext).Tenant.Id 6> $null | |
| $environmentUsage | Select-Object @{ name="EnvironmentName"; Expression={ $environment.DisplayName }}, EnvironmentId, SubnetName, SubnetIpRange, ContainerReservedIpCount, @{ name="DnsServers"; Expression={ $_.DnsServers -join "," }} | |
| } | |
| # export to csv | |
| $timestamp = Get-Date -Format filedatetime | |
| $environmentSubnetUsage | Export-Csv -Path "EnvironmentSubnetUsage_$timestamp.csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment