Modules/users.psm1
#get /rest/v1.0/dd-systems/{SYSTEM-ID}/users function Get-DDUsers { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)] [string]$id, [Parameter(Mandatory = $false, ParameterSetName = 'byID')] [Parameter(Mandatory = $false, ParameterSetName = 'default')] [string] $SYSTEM_ID = $Global:DD_UUID, $body = @{size= 9999} ) begin { $Response = @() $METHOD = "GET" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "api/v2" $uri = "dd-systems/$($SYSTEM_ID)/users" } 'byID' { $apiver = "api/v2" $uri = "dd-systems/$($SYSTEM_ID)/users/$ID" $body= @{} } } $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'default' { $response.user| Select-Object -ExcludeProperty link } 'byID' { $response | Select-Object -Property * -ExcludeProperty link } } } } #POST/rest/v1.0/dd-systems/{SYSTEM-ID}/users function New-DDUser { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'default', ValueFromPipelineByPropertyName = $true)] [string]$Name, [Parameter(Mandatory = $false, ParameterSetName = 'default')] [ValidateSet( "none", "admin", "mobile-user", "backup-operator", "user", "limited-admin", "security")] [string] $UserRole, [Parameter(Mandatory = $true, ParameterSetName = 'default')] [securestring]$password, $SYSTEM_ID = $Global:DD_UUID, [switch]$ForcePasswordChange, $body = @{} ) begin { $Response = @() $METHOD = "POST" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "api/v2" $uri = "dd-systems/$($SYSTEM_ID)/users" } } $json=@{ role = $userrole name = $name password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) force_password_change = $ForcePasswordChange.IsPresent } | convertto-json write-verbose ($json | out-string) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $json RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } write-verbose ($parameters | out-string) try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'default' { $response | Select-Object -ExcludeProperty link } 'byID' { $response | Select-Object -Property * -ExcludeProperty link } } } } # Put /rest/v1.0/dd-systems/{SYSTEM-ID}/users/{ID} function Set-DDUserPassword { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'default', ValueFromPipelineByPropertyName = $true)] [string]$id, [Parameter(Mandatory = $true, ParameterSetName = 'default')] [securestring]$NewPassword, [Parameter(Mandatory = $false, ParameterSetName = 'default')] [securestring]$CurrentPassword, $SYSTEM_ID = $Global:DD_UUID ) begin { $Response = @() $METHOD = "PUT" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/users/$($id)" } } $json=@{ new_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Newpassword)) } If ($CurrentPassword) { $json.Add('current_password',[System.Runtime.InteropServices.Marshal]::PtrToStringBSTR([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Currentpassword))) } $json= $json| convertto-json write-verbose ($json | out-string) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $json RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'default' { $response| Select-Object * -ExcludeProperty link } 'byID' { $response | Select-Object -Property * -ExcludeProperty link } } } } # DELETE /rest/v1.0/dd-systems/{SYSTEM-ID}/users/{ID} function Remove-DDUser { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'byID')] [string][alias('user_id')]$id, [string] $SYSTEM_ID = $Global:DD_UUID ) begin { $Response = @() $METHOD = "DELETE" $apiver = "rest/v1.0" } process { switch ($PsCmdlet.ParameterSetName) { default { $uri = "dd-systems/$($SYSTEM_ID)/users/$ID" } } $body = $body | ConvertTo-Json Write-Verbose ($body | Out-String) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response | Select-Object -ExcludeProperty links, link, paging_info } } } } |