Public/Set-OnePAMResource.ps1
|
function Set-OnePAMResource { <# .SYNOPSIS Updates an existing OnePAM resource. .DESCRIPTION Modifies one or more properties of an existing resource by its ID. .PARAMETER Id The UUID of the resource to update. .PARAMETER Name New display name. .PARAMETER TargetHost New target hostname or IP. .PARAMETER Port New target port. .PARAMETER AgentId New agent endpoint UUID. .EXAMPLE Set-OnePAMResource -Id "abc-123" -Name "staging-db" -Port 5433 #> [CmdletBinding()] param( [Parameter(Mandatory)] [string]$Id, [string]$Name, [Alias('Host')] [string]$TargetHost, [int]$Port, [string]$AgentId ) Assert-OpSafePathSegment -Value $Id -Label 'resource ID' $body = @{} if ($Name) { $body['name'] = $Name } if ($TargetHost) { $body['host'] = $TargetHost } if ($Port -gt 0) { $body['port'] = $Port } if ($AgentId) { $body['agent_id'] = $AgentId } if ($body.Count -eq 0) { throw 'At least one property to update must be specified.' } $encoded = [System.Uri]::EscapeDataString($Id) $resp = Invoke-OpApi -Method PUT -Path "/api/v1/resources/$encoded" -Body $body if ($resp.resource) { return $resp.resource } $resp } |