Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding limit and select aliases - GA commands #1218

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
84 changes: 45 additions & 39 deletions module/Entra/AdditionalFunctions/Get-EntraAdministrativeUnit.ps1
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Get-EntraAdministrativeUnit {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Alias("ObjectId")]
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $AdministrativeUnitId,
[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
[Alias("ObjectId")]
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $AdministrativeUnitId,

[Alias("Limit")]
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable[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["AdministrativeUnitId"])
{
$params["AdministrativeUnitId"] = $PSBoundParameters["AdministrativeUnitId"]
$params["Uri"] = "$baseUri/$($params.AdministrativeUnitId)?$properties"
}
if ($PSBoundParameters.ContainsKey("Top")) {
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
$params["Uri"] += "&`$top=999"
PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$baseUri = "/v1.0/directory/administrativeUnits"
$properties = '$select=*'
$params["Uri"] = "$baseUri/?$properties"

if ($null -ne $PSBoundParameters["AdministrativeUnitId"]) {
$params["AdministrativeUnitId"] = $PSBoundParameters["AdministrativeUnitId"]
$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"]) {
$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)

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

try {
Expand All @@ -59,18 +65,18 @@ function Get-EntraAdministrativeUnit {
$params["Uri"] = $params["Uri"].Replace('$top=999', "`$top=$topValue")
$increment -= $topValue
}
$response = Invoke-GraphRequest @params
$response = Invoke-GraphRequest @params
$data += $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json
}
}
catch {}
} 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
}
}

if ($data) {
$aulist = @()
foreach ($item in $data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Get-EntraAdministrativeUnitMember {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable`1[System.Int32]] $Top,
[Alias("ObjectId")]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $AdministrativeUnitId,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All
param (
[Alias("Limit")]
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Nullable[System.Int32]] $Top,

[Alias("ObjectId")]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $AdministrativeUnitId,

[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[switch] $All
)

PROCESS {
Expand All @@ -19,17 +23,17 @@ function Get-EntraAdministrativeUnitMember {
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$baseUri = "/v1.0/directory/administrativeUnits/$AdministrativeUnitId/members?`$select=*"
$params["Uri"] = "$baseUri"
if($null -ne $PSBoundParameters["AdministrativeUnitId"])
{

if ($null -ne $PSBoundParameters["AdministrativeUnitId"]) {
$params["AdministrativeUnitId"] = $PSBoundParameters["AdministrativeUnitId"]
}

if ($PSBoundParameters.ContainsKey("Top")) {
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
$minTop = 999
$params["Uri"] += "&`$top=999"
}
else {
} else {
$params["Uri"] += "&`$top=$topCount"
}
}
Expand All @@ -38,7 +42,7 @@ function Get-EntraAdministrativeUnitMember {
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")

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

try {
Expand All @@ -51,22 +55,22 @@ function Get-EntraAdministrativeUnitMember {
$topValue = [Math]::Min($increment, 999)
if ($minTop) {
$params["Uri"] = $params["Uri"].Replace("`$top=$minTop", "`$top=$topValue")
}
else {
} else {
$params["Uri"] = $params["Uri"].Replace("`$top=$topCount", "`$top=$topValue")
}
$increment -= $topValue
}
$response = (Invoke-GraphRequest -Headers $customHeaders -Uri $($params.Uri) -Method GET)
$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 $_) {
Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id
}
}

if ($data) {
$memberList = @()
foreach ($response in $data) {
Expand Down
55 changes: 28 additions & 27 deletions module/Entra/AdditionalFunctions/Get-EntraApplicationTemplate.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Get-EntraApplicationTemplate {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,
[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,
[Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)]
[System.String[]] $Property
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,

[Alias("Limit")]
[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,

[Alias("Select")]
[Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)]
[System.String[]] $Property
)

PROCESS {
Expand All @@ -22,48 +29,42 @@ function Get-EntraApplicationTemplate {
$topCount = $null
$uri = "https://graph.microsoft.com/v1.0/applicationTemplates"
$params["Method"] = "GET"
$params["Uri"] = $uri+'?$select=*'
$params["Uri"] = $uri + '?$select=*'

if($null -ne $PSBoundParameters["Property"])
{
if ($null -ne $PSBoundParameters["Property"]) {
$selectProperties = $PSBoundParameters["Property"]
$selectProperties = $selectProperties -Join ','
$params["Uri"] = $uri+"?`$select=$($selectProperties)"
$params["Uri"] = $uri + "?`$select=$($selectProperties)"
}
if(($PSBoundParameters.ContainsKey("Top") -and (-not $PSBoundParameters.ContainsKey("All"))) -or ($PSBoundParameters.ContainsKey("Top") -and $null -ne $PSBoundParameters["All"]))
{
$topCount = $PSBoundParameters["Top"]
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"
}
if($null -ne $PSBoundParameters["Filter"])
{
if ($null -ne $PSBoundParameters["Filter"]) {
$Filter = $PSBoundParameters["Filter"]
$f = '$' + 'Filter'
$params["Uri"] += "&$f=$Filter"
}
if((-not $PSBoundParameters.ContainsKey("Top")) -and (-not $PSBoundParameters.ContainsKey("All")))
{
if ((-not $PSBoundParameters.ContainsKey("Top")) -and (-not $PSBoundParameters.ContainsKey("All"))) {
$params["Uri"] += "&`$top=100"
}
if($null -ne $PSBoundParameters["Id"])
{
if ($null -ne $PSBoundParameters["Id"]) {
$params["ApplicationTemplateId"] = $PSBoundParameters["Id"]
$params["Uri"] = $uri + "/$Id"
}

$response = Invoke-GraphRequest -Uri $($params.Uri) -Method GET -Headers $customHeaders

if($response.ContainsKey('value')){
if ($response.ContainsKey('value')) {
$response = $response.value
}

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

$userList = @()
foreach ($res in $data) {
$userType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphApplicationTemplate
$res.PSObject.Properties | ForEach-Object {
$propertyName = $_.Name.Substring(0,1).ToUpper() + $_.Name.Substring(1)
$propertyName = $_.Name.Substring(0, 1).ToUpper() + $_.Name.Substring(1)
$propertyValue = $_.Value
$userType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force
}
Expand Down
40 changes: 20 additions & 20 deletions module/Entra/AdditionalFunctions/Get-EntraAuditDirectoryLog.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------

function Get-EntraAuditDirectoryLog {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetById", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,
[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
[Parameter(ParameterSetName = "GetById", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,

[Alias("Limit")]
[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 {
Expand All @@ -21,32 +25,28 @@ function Get-EntraAuditDirectoryLog {
$topCount = $null
$baseUri = 'https://graph.microsoft.com/v1.0/auditLogs/directoryAudits'
$params["Method"] = "GET"
$params["Uri"] = "$baseUri"+"?"
$params["Uri"] = "$baseUri" + "?"

if($PSBoundParameters.ContainsKey("Top"))
{
if ($PSBoundParameters.ContainsKey("Top")) {
$topCount = $PSBoundParameters["Top"]
if ($topCount -gt 999) {
$params["Uri"] += "&`$top=999"
}
else{
} else {
$params["Uri"] += "&`$top=$topCount"
}
}
if($null -ne $PSBoundParameters["Id"])
{
if ($null -ne $PSBoundParameters["Id"]) {
$LogId = $PSBoundParameters["Id"]
$params["Uri"] = "$baseUri/$($LogId)"
}
if($null -ne $PSBoundParameters["Filter"])
{
if ($null -ne $PSBoundParameters["Filter"]) {
$Filter = $PSBoundParameters["Filter"]
$f = '$Filter'
$params["Uri"] += "&$f=$Filter"
}

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

$response = Invoke-GraphRequest @params -Headers $customHeaders
Expand Down
Loading