Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions module/Entra/AdditionalFunctions/Find-EntraPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ function Find-EntraPermission {
{
$params["WarningAction"] = $PSBoundParameters["WarningAction"]
}
if($null -ne $PSBoundParameters["Top"])
{
$params["Top"] = $PSBoundParameters["Top"]
}

Write-Debug("============================ TRANSFORMATIONS ============================")
$params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug
Expand Down
144 changes: 68 additions & 76 deletions module/Entra/AdditionalFunctions/Get-EntraAdministrativeUnit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,84 @@
function Get-EntraAdministrativeUnit {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $ObjectId,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable`1[System.Int32]] $Top,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Filter
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $ObjectId,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Int32] $Top,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Filter
)

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$baseUri = "/v1.0/directory/administrativeUnits"
$properties = '$select=*'
$params["Uri"] = "$baseUri/?$properties"
if($null -ne $PSBoundParameters["ObjectId"])
{
$params["AdministrativeUnitId"] = $PSBoundParameters["ObjectId"]
$params["Uri"] = "$baseUri/$($params.AdministrativeUnitId)?$properties"
}
if($null -ne $PSBoundParameters["All"])
{
$uri = $baseUri
}
if($null -ne $PSBoundParameters["Top"] -and (-not $PSBoundParameters.ContainsKey("All")))
{
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
$params["Uri"] += "&`$top=999"
$params = @{}
$topCount = $null
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$baseUri = "/v1.0/directory/administrativeUnits"
$properties = '$select=*'
$params["Uri"] = "$baseUri/?$properties"
if ($null -ne $PSBoundParameters["ObjectId"]) {
$params["AdministrativeUnitId"] = $PSBoundParameters["ObjectId"]
$params["Uri"] = "$baseUri/$($params.AdministrativeUnitId)?$properties"
}
else{
$params["Uri"] += "&`$top=$topCount"
if ($PSBoundParameters.ContainsKey("Top")) {
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
$params["Uri"] += "&`$top=999"
}
else {
$params["Uri"] += "&`$top=$topCount"
}
}
if ($null -ne $PSBoundParameters["Filter"]) {
$Filter = $PSBoundParameters["Filter"]
$f = '$' + 'Filter'
$params["Uri"] += "&$f=$Filter"
}
}
if($null -ne $PSBoundParameters["Filter"])
{
$params["Filter"] = $PSBoundParameters["Filter"]
$Filter = $PSBoundParameters["Filter"]
$f = '$' + 'Filter'
$params["Uri"] += "&$f=$Filter"
}

Write-Debug("============================ TRANSFORMATIONS ============================")
$params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")

$response = (Invoke-GraphRequest -Headers $customHeaders -Uri $($params.Uri) -Method GET)
if($response.ContainsKey('value')){
$response = $response.value
}

$data = $response | ConvertTo-Json -Depth 10 | ConvertFrom-Json
Write-Debug("============================ TRANSFORMATIONS ============================")
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")

$response = (Invoke-GraphRequest -Headers $customHeaders -Uri $($params.Uri) -Method GET)
$data = $response | ConvertTo-Json -Depth 10 | ConvertFrom-Json

try {
$data = $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
$all = $All.IsPresent
$increment = $topCount - $data.Count
while ($response.'@odata.nextLink' -and (($all) -or ($increment -gt 0 -and -not $all))) {
$URI = $response.'@odata.nextLink'
if (-not $all) {
$topValue = [Math]::Min($increment, 999)
$URI = $URI.Replace('$top=999', "`$top=$topValue")
$increment -= $topValue
try {
$data = $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
$all = $All.IsPresent
$increment = $topCount - $data.Count
while (($response.'@odata.nextLink' -and (($all -and ($increment -lt 0)) -or $increment -gt 0))) {
$params["Uri"] = $response.'@odata.nextLink'
if ($increment -gt 0) {
$topValue = [Math]::Min($increment, 999)
$params["Uri"] = $params["Uri"].Replace('$top=999', "`$top=$topValue")
$increment -= $topValue
}
$response = Invoke-GraphRequest @params
$data += $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
}
$response = Invoke-GraphRequest -Uri $URI -Method $Method
$data += $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
}
} catch {}
$data | ForEach-Object {
if($null -ne $_) {
Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id
Add-Member -InputObject $_ -MemberType AliasProperty -Name DeletionTimeStamp -Value deletedDateTime
catch {}
$data | ForEach-Object {
if ($null -ne $_) {
Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id
Add-Member -InputObject $_ -MemberType AliasProperty -Name DeletionTimeStamp -Value deletedDateTime
}
}
}

$aulist = @()
foreach($item in $data){
$auType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAdministrativeUnit
$item.PSObject.Properties | ForEach-Object {
$propertyName = $_.Name.Substring(0,1).ToUpper() + $_.Name.Substring(1)
$propertyValue = $_.Value
$auType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force

if ($data) {
$aulist = @()
foreach ($item in $data) {
$auType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAdministrativeUnit
$item.PSObject.Properties | ForEach-Object {
$propertyName = $_.Name.Substring(0, 1).ToUpper() + $_.Name.Substring(1)
$propertyValue = $_.Value
$auType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force
}
$aulist += $auType
}
$aulist
}
$aulist += $auType
}
$aulist
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,68 @@
function Get-EntraAdministrativeUnitMember {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable`1[System.Int32]] $Top,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $ObjectId,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Int32] $Top,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $ObjectId,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All
)

PROCESS {
$params = @{}
$topCount = $null
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$baseUri = "/v1.0/directory/administrativeUnits/$ObjectId/members?`$select=*"
$params["Uri"] = "$baseUri"
if($null -ne $PSBoundParameters["ObjectId"])
{
if ($null -ne $PSBoundParameters["ObjectId"]) {
$params["AdministrativeUnitId"] = $PSBoundParameters["ObjectId"]
}
if($null -ne $PSBoundParameters["All"])
{
$uri = $baseUri
}
if($null -ne $PSBoundParameters["Top"] -and (-not $PSBoundParameters.ContainsKey("All")))
{
if ($PSBoundParameters.ContainsKey("Top")) {
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
$minTop = 999
$params["Uri"] += "&`$top=999"
}
else{
else {
$params["Uri"] += "&`$top=$topCount"
}
}

Write-Debug("============================ TRANSFORMATIONS ============================")
$params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")

$response = (Invoke-GraphRequest -Headers $customHeaders -Uri $($params.Uri) -Method GET)
if($response.ContainsKey('value')){
$response = $response.value
}

$data = $response | ConvertTo-Json -Depth 10 | ConvertFrom-Json

try {
$data = $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
$all = $All.IsPresent
$increment = $topCount - $data.Count
while ($response.'@odata.nextLink' -and (($all) -or ($increment -gt 0 -and -not $all))) {
$URI = $response.'@odata.nextLink'
if (-not $all) {
while (($response.'@odata.nextLink' -and (($all -and ($increment -lt 0)) -or $increment -gt 0))) {
$params["Uri"] = $response.'@odata.nextLink'
if ($increment -gt 0) {
$topValue = [Math]::Min($increment, 999)
$URI = $URI.Replace('$top=999', "`$top=$topValue")
if ($minTop) {
$params["Uri"] = $params["Uri"].Replace("`$top=$minTop", "`$top=$topValue")
}
else {
$params["Uri"] = $params["Uri"].Replace("`$top=$topCount", "`$top=$topValue")
}
$increment -= $topValue
}
$response = Invoke-GraphRequest -Uri $URI -Method $Method
$response = (Invoke-GraphRequest -Headers $customHeaders -Uri $($params.Uri) -Method GET)
$data += $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
}
} catch {}
}
catch {}
$data | ForEach-Object {
if($null -ne $_) {
if ($null -ne $_) {
Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id
}
}
if($data){
if ($data) {
$memberList = @()
foreach ($response in $data) {
$memberType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphDirectoryObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-EntraApplicationTemplate {
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable`1[System.Int32]] $Top,
[System.Int32] $Top,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
Expand All @@ -30,7 +30,7 @@ function Get-EntraApplicationTemplate {
$selectProperties = $selectProperties -Join ','
$params["Uri"] = $uri+"?`$select=$($selectProperties)"
}
if(($null -ne $PSBoundParameters["Top"] -and (-not $PSBoundParameters.ContainsKey("All"))) -or ($null -ne $PSBoundParameters["Top"] -and $null -ne $PSBoundParameters["All"]))
if(($PSBoundParameters.ContainsKey("Top") -and (-not $PSBoundParameters.ContainsKey("All"))) -or ($PSBoundParameters.ContainsKey("Top") -and $null -ne $PSBoundParameters["All"]))
{
$topCount = $PSBoundParameters["Top"]
$params["Uri"] += "&`$top=$topCount"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Get-EntraAuditDirectoryLog {
$params["Method"] = "GET"
$params["Uri"] = "$baseUri"+"?"

if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Get-EntraAuditSignInLog {
$params["Uri"] = "$baseUri"
$query = $null

if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
Expand Down
4 changes: 2 additions & 2 deletions module/Entra/AdditionalFunctions/Get-EntraObjectSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Get-EntraObjectSetting {
param (
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)][System.String] $Id,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable`1[System.Int32]] $Top,
[System.Int32] $Top,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
Expand All @@ -30,7 +30,7 @@ function Get-EntraObjectSetting {
$selectProperties = $selectProperties -Join ','
$params["Uri"] = $baseUri+"?`$select=$($selectProperties)"
}
if($null -ne $PSBoundParameters["Top"] -and (-not $PSBoundParameters.ContainsKey("All")))
if($PSBoundParameters.ContainsKey("Top") -and (-not $PSBoundParameters.ContainsKey("All")))
{
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
Expand Down
8 changes: 7 additions & 1 deletion module/Entra/AdditionalFunctions/Get-EntraPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Get-EntraPolicy {
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable`1[System.Int32]] $Top,
[System.Int32] $Top,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All
)
Expand All @@ -19,6 +19,12 @@ function Get-EntraPolicy {
$baseUrl = "https://graph.microsoft.com/v1.0/policies/"
$endpoints = @("homeRealmDiscoveryPolicies", "claimsMappingPolicies", "tokenIssuancePolicies", "tokenLifetimePolicies", "activityBasedTimeoutPolicies", "featureRolloutPolicies", "defaultAppManagementPolicy", "appManagementPolicies", "authenticationFlowsPolicy", "authenticationMethodsPolicy", "permissionGrantPolicies")

if($PSBoundParameters.ContainsKey("Top") -and ($null -eq $Top -or $Top -eq 0)){
Write-Error "Invalid page size specified: '0'. Must be between 1 and 999 inclusive.
Status: 400 (BadRequest)
ErrorCode: Request_UnsupportedQuery"
break
}
$response = @()
foreach ($endpoint in $endpoints) {
$url = "${baseUrl}${endpoint}"
Expand Down
2 changes: 1 addition & 1 deletion module/Entra/customizations/Get-EntraApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{
$params["Debug"] = $PSBoundParameters["Debug"]
}
if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$params["Top"] = $PSBoundParameters["Top"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
$URI = "$baseUri/$($params.ApplicationId)/owners?$properties"
}
if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$topCount = $PSBoundParameters["Top"]
$URI = "$baseUri/$($params.ApplicationId)/owners?`$top=$topCount&$properties"
Expand Down
2 changes: 1 addition & 1 deletion module/Entra/customizations/Get-EntraContact.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
$params["Debug"] = $PSBoundParameters["Debug"]
}
if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$params["Top"] = $PSBoundParameters["Top"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
$params["Debug"] = $PSBoundParameters["Debug"]
}

if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$params["Top"] = $PSBoundParameters["Top"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
$URI = "$baseUri/$($params.DeviceId)/registeredOwners?$properties"
}
if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$topCount = $PSBoundParameters["Top"]
$URI = "$baseUri/$($params.DeviceId)/registeredOwners?`$top=$topCount&$properties"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
$URI = "$baseUri/$($params.DeviceId)/registeredUsers?$properties"
}
if($null -ne $PSBoundParameters["Top"])
if($PSBoundParameters.ContainsKey("Top"))
{
$topCount = $PSBoundParameters["Top"]
$URI = "$baseUri/$($params.DeviceId)/registeredUsers?`$top=$topCount&$properties"
Expand Down
Loading