Scripts/Remove-BPAPermission.ps1
function Remove-BPAPermission { <# .SYNOPSIS Removes AutoMate BPA permissions. .DESCRIPTION Remove-BPAPermission removes the provided permissions. .PARAMETER InputObject The permissions object(s) to remove. .INPUTS Permission objects are deleted by this function. .EXAMPLE # Remove system permissions for user "MyUsername" Get-BPAFolder "FTP Workflows" | Get-BPAPermission | Remove-BPAPermission .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 02/09/2018 Date Modified : 06/07/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')] param( [Parameter(Position = 0, ParameterSetName = "ByPipeline", ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] $InputObject ) PROCESS { :objectloop foreach ($obj in $InputObject) { switch ($obj.TypeName) { "Permission" { $construct = Get-BPAObject -ID $obj.ConstructID if (($construct | Measure-Object).Count -eq 1) { $affectedUser = Get-BPAObject -ID $obj.GroupID -Types User,UserGroup if (($affectedUser | Measure-Object).Count -eq 1) { if ($PSCmdlet.ShouldProcess($obj.BPAServer, "Removing permission from $($construct.TypeName) '$($construct.Name)': $($affectedUser.Name)")) { Write-Verbose "Removing permission from $($construct.TypeName) '$($construct.Name)' for '$($affectedUser.Name) (Type: $($affectedUser.TypeName))'." Invoke-BPARestMethod -Resource "$(([BPATypeDictionary]::$($construct.TypeName)).RestResource)/$($obj.ConstructID)/permissions/$($obj.ID)/delete" -RestMethod Post | Out-Null } } else { Write-Warning "Multiple objects found for user/group ID $($obj.ConstructID)! No action will be taken." continue objectloop } } else { Write-Warning "Multiple objects found for construct ID $($obj.ConstructID)! No action will be taken." continue objectloop } } default { Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj } } } } } |