functions/Add-User.ps1
<#
.SYNOPSIS Create a user based on name parameter and user type. .DESCRIPTION Adds a single user using the create user endpoint, but allows for declaration of the following types in the cmdlet: local ldap saml This cmdlet sets the user property to be enabled by default. .EXAMPLE Add-User "My User" "myPW!!" "local" #> Function Add-User { [cmdletbinding()] param( [Parameter(Mandatory=$true)] [string]$NewUserName, [Parameter(Mandatory=$true)] [string]$NewPassword, [Parameter(Mandatory=$true)] [string]$NewUserType, [string]$IsAdmin ) $endpoint = switch ($NewUserType){ "local" {"/api/admin/users/local";break} "ldap" {"/api/admin/users/ldap";break} "saml" {"/api/admin/users/external";break} default {"500";break} } If ($endpoint -eq 500){ Return "User Type $NewUserType not recognized!" } $uri = $CDXSERVER + $endpoint $JSON = ConvertTo-Json @{ name = $NewUserName password = $NewPassword enabled = "true" clientType = $NewUserType } $AddUser = Invoke-RestMethod -Uri $uri -Method Post -Body $JSON -Headers $headers -ContentType "application/json" Write-Verbose ( $AddUser | Format-Table | Out-String ) If ($IsAdmin -eq "true"){ Set-AdminUser $AddUser.id "true" } $AddUser } |