Functions/Public/Get-AMSystemPermission.ps1
function Get-AMSystemPermission { <# .SYNOPSIS Gets Automate system permissions. .DESCRIPTION Get-AMSystemPermission gets system permissions. .PARAMETER InputObject The object(s) to retrieve permissions for. .PARAMETER FilterSet The parameters to filter the search on. Supply hashtable(s) with the following properties: Property, Operator, Value. Valid values for the Operator are: =, !=, <, >, contains (default - no need to supply Operator when using 'contains') .PARAMETER FilterSetMode If multiple filter sets are provided, FilterSetMode determines if the filter sets should be evaluated with an AND or an OR .PARAMETER SortProperty The object property to sort results on. Do not use ConnectionAlias, since it is a custom property added by this module, and not exposed in the API. .PARAMETER SortDescending If specified, this will sort the output on the specified SortProperty in descending order. Otherwise, ascending order is assumed. .PARAMETER Connection The Automate management server. .PARAMETER ID The ID of the system permission object. .INPUTS Permissions for the following objects can be retrieved by this function: User UserGroup .OUTPUTS SystemPermission .EXAMPLE # Get permissions for user "MyUsername" Get-AMUser "MyUsername" | Get-AMSystemPermission .EXAMPLE # Get permissions using filter sets Get-AMSystemPermission -FilterSet @{Property = 'EditDefaultPropertiesPermission'; Operator = '='; Value = 'true'} .LINK https://github.com/AutomatePS/AutomatePS/blob/master/Docs/Get-AMSystemPermission.md #> [CmdletBinding(DefaultParameterSetName="All")] [OutputType([AMSystemPermissionv10],[AMSystemPermissionv11])] param ( [Parameter(Position = 0, ParameterSetName = "ByPipeline", ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] $InputObject, [Parameter(ParameterSetName = "ByID")] [ValidateNotNullOrEmpty()] [string]$ID, [ValidateNotNull()] [Hashtable[]]$FilterSet = @(), [ValidateSet("And","Or")] [string]$FilterSetMode = "And", [ValidateNotNullOrEmpty()] [string[]]$SortProperty = "GroupID", [ValidateNotNullOrEmpty()] [switch]$SortDescending = $false, [ValidateNotNullOrEmpty()] [ArgumentCompleter([AMConnectionCompleter])] $Connection ) BEGIN { $splat = @{ RestMethod = "Get" } if ($PSBoundParameters.ContainsKey("Connection")) { $Connection = Get-AMConnection -Connection $Connection $splat += @{Connection = $Connection} } $result = @() } PROCESS { switch($PSCmdlet.ParameterSetName) { "All" { $splat += @{ Resource = Format-AMUri -Path "system_permissions/list" -FilterSet $FilterSet -FilterSetMode $FilterSetMode -SortProperty $SortProperty -SortDescending:$SortDescending.ToBool() } $result = Invoke-AMRestMethod @splat } "ByID" { $splat += @{ Resource = "system_permissions/$ID/get" } $result = Invoke-AMRestMethod @splat } "ByPipeline" { foreach ($obj in $InputObject) { Write-Verbose "Processing $($obj.Type) '$($obj.Name)'" $tempSplat = $splat if (-not $tempSplat.ContainsKey("Connection")) { $tempSplat += @{ Connection = $obj.ConnectionAlias } } else { $tempSplat["Connection"] = $obj.ConnectionAlias } Write-Verbose "Processing $($obj.Type) '$($obj.Name)'" switch ($obj.Type) { {($_ -in @("User","UserGroup"))} { $tempFilterSet = $FilterSet + @{Property = "GroupID"; Operator = "="; Value = $obj.ID} $tempSplat += @{ Resource = Format-AMUri -Path "system_permissions/list" -FilterSet $tempFilterSet -FilterSetMode $FilterSetMode -SortProperty $SortProperty -SortDescending:$SortDescending.ToBool() } $result += Invoke-AMRestMethod @tempSplat } default { $unsupportedType = $obj.GetType().FullName if ($_) { $unsupportedType = $_ } elseif (-not [string]::IsNullOrEmpty($obj.Type)) { $unsupportedType = $obj.Type } Write-Error -Message "Unsupported input type '$unsupportedType' encountered!" -TargetObject $obj } } } } } } END { $SortProperty += "ConnectionAlias", "ID" return $result | Sort-Object $SortProperty -Unique -Descending:$SortDescending.ToBool() } } |