Public/Get-OnePAMResource.ps1
|
function Get-OnePAMResource { <# .SYNOPSIS Lists or retrieves OnePAM resources. .DESCRIPTION Without parameters, lists all resources the user has access to. With -Name or -Id, retrieves a specific resource with full details. With -Type, filters resources by type (ssh, rdp, database, https). .PARAMETER Name Resource name to look up (resolves by name then by ID). .PARAMETER Id Resource UUID to retrieve directly. .PARAMETER Type Filter resources by type (ssh, rdp, database, https). .EXAMPLE Get-OnePAMResource .EXAMPLE Get-OnePAMResource -Name "prod-db" .EXAMPLE Get-OnePAMResource -Type database #> [CmdletBinding(DefaultParameterSetName = 'List')] param( [Parameter(ParameterSetName = 'ByName')] [string]$Name, [Parameter(ParameterSetName = 'ById')] [string]$Id, [Parameter(ParameterSetName = 'List')] [ValidateSet('ssh', 'rdp', 'database', 'https')] [string]$Type ) if ($Name) { $encoded = [System.Uri]::EscapeDataString($Name) $resp = Invoke-OpApi -Method GET -Path "/api/v1/resources?name=$encoded" if ($resp.resources -and $resp.resources.Count -eq 1) { return $resp.resources[0] } if ($resp.resources -and $resp.resources.Count -gt 1) { throw "Multiple resources match '$Name'. Use -Id with the resource UUID instead." } try { $resp = Invoke-OpApi -Method GET -Path "/api/v1/resources/$encoded" if ($resp.resource) { return $resp.resource } return $resp } catch { throw "Resource '$Name' not found." } } if ($Id) { $resp = Invoke-OpApi -Method GET -Path "/api/v1/resources/$([System.Uri]::EscapeDataString($Id))" if ($resp.resource) { return $resp.resource } return $resp } $path = '/api/v1/resources' if ($Type) { $path += "?type=$([System.Uri]::EscapeDataString($Type))" } $resp = Invoke-OpApi -Method GET -Path $path if ($resp.resources) { return $resp.resources } return @() } |