functions/folder-permissions/Update-FolderPermission.ps1
function Update-FolderPermission { <# .SYNOPSIS Update properties for a given FolderPermission .DESCRIPTION Update properties for a given FolderPermission .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Update-TssFolderPermission -TssSession $session -Id 34 -FolderId 5 -FolderAccessRoleName Edit -SecretAccessRoleName View Update Folder Permission ID 34 on Folder ID 5 to Edit folder permission and View secret permission .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Update-TssFolderPermission -TssSession $session -Id 45 -FolderId 72 -FolderAccessRoleName Owner Update Folder Permission ID 45 on Folder ID 72 to Owner folder permission .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/folder-permissions/Update-TssFolderPermission .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/folder-permissions/Update-FolderPermission.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [cmdletbinding(SupportsShouldProcess)] [OutputType()] param( # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [TssSession]$TssSession, # Folder Permission Id to modify [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('FolderPermissionId')] [int[]] $Id, # Folder ID [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [int] $FolderId, # Role to grant on the folder: View, Edit, Add Secret, Owner [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [ValidateSet('View', 'Edit', 'Add Secret', 'Owner')] [string] $FolderAccessRolename, # Role to grant on the secret: View, Edit, List, Owner [ValidateSet('View', 'Edit', 'List', 'Owner','None')] [string] $SecretAccessRoleName, # Allow updating of inherited permissions [switch] $BreakInheritance ) begin { $setParams = $PSBoundParameters $invokeParams = . $GetInvokeTssParams $TssSession } process { Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { . $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation foreach ($folderPermission in $Id) { $restResponse = $null $uri = $TssSession.ApiUrl, 'folder-permissions', $folderPermission -join '/' $invokeParams.Uri = $uri $invokeParams.Method = 'PUT' $setBody = @{ id = $folderPermission folderId = $FolderId folderAccessRoleName = $FolderAccessRoleName } if ($setParams.ContainsKey('SecretAccessRoleName')) { $setBody.Add('secretAccessRoleName', $SecretAccessRoleName) } if ($setParams.ContainsKey('BreakInheritance')) { $setBody.Add('breakInheritance', [boolean]$BreakInheritance) } $invokeParams.Body = $setBody | ConvertTo-Json if ($PSCmdlet.ShouldProcess("FolderPermissionID: ${5}", "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n")) { Write-Verbose "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n" try { $restResponse = . $InvokeApi @invokeParams } catch { Write-Warning 'Issue setting property on folder permission [$folderPermission]' $err = $_ . $ErrorHandling $err } } if ($restResponse) { [TssFolderPermissionSummary]$restResponse } } } else { Write-Warning 'No valid session found' } } } |