Functions/User/Add-PASGroupMember.ps1
function Add-PASGroupMember { <# .SYNOPSIS Adds a vault user as a group member .DESCRIPTION Adds an existing user to an existing group in the vault .PARAMETER GroupName The name of the user .PARAMETER UserName The name of the user .PARAMETER sessionToken Hashtable containing the session token returned from New-PASSession .PARAMETER WebSession WebRequestSession object returned from New-PASSession .PARAMETER BaseURI PVWA Web Address Do not include "/PasswordVault/" .PARAMETER PVWAAppName The name of the CyberArk PVWA Virtual Directory. Defaults to PasswordVault .EXAMPLE $token | Add-PASGroupMember -GroupName PVWAMonitor -UserName TargetUser Adds TargetUser to PVWAMonitor group .INPUTS All parameters can be piped by property name .OUTPUTS None .NOTES .LINK #> [CmdletBinding()] param( [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true )] [string]$GroupName, [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true )] [string]$UserName, [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true )] [ValidateNotNullOrEmpty()] [hashtable]$sessionToken, [parameter( ValueFromPipelinebyPropertyName = $true )] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true )] [string]$BaseURI, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true )] [string]$PVWAAppName = "PasswordVault" ) BEGIN {}#begin PROCESS { #Create URL for request $URI = "$baseURI/$PVWAAppName/WebServices/PIMServices.svc/Groups/$($GroupName | Get-EscapedString)/Users" #create request body $Body = $PSBoundParameters | Get-PASParameter -ParametersToRemove GroupName | ConvertTo-Json #send request to web service $result = Invoke-PASRestMethod -Uri $URI -Method POST -Body $Body -Headers $sessionToken -WebSession $WebSession if($result) { $result } }#process END {}#end } |