Skip to content

Instantly share code, notes, and snippets.

@hbulens
Last active December 16, 2021 15:38
Show Gist options
  • Save hbulens/fa47d6f04875795f7b23571190571a9f to your computer and use it in GitHub Desktop.
Save hbulens/fa47d6f04875795f7b23571190571a9f to your computer and use it in GitHub Desktop.
Creates a new user in Dime.Scheduler

About

Unofficial script to create a Dime.Scheduler user. Check the Dime.Scheduler CLI for the official and supported way to provision users.

Example

New-Dime.SchedulerUser `
-DisplayName "Name of the user" `
-EmailAddress "user@email.com" `
-Language en `
-TimeZone "Europe/London" `
-DimeSchedulerUrl https://myurl
function New-DimeSchedulerUser
{
<#
.Synopsis
Creates a new application user in the Dime.Scheduler application.
.DESCRIPTION
Creates a new application user in the Dime.Scheduler application.
.PARAMETER DisplayName
Specifies the full name of the user, the key is assigned to.
.PARAMETER EmailAddress
Specifies the email address of the user, the key is assigned to.
.PARAMETER Language
Specifies the two letter localization code (nl for Dutch, en for English, etc.)
.PARAMETER TimeZone
Specifies the timezone (e.g. Europe/Amsterdam)
.PARAMETER DimeSchedulerUrl
URL to the Dime.Scheduler application
.PARAMETER DimeSchedulerUserName
Username for a Dime.Scheduler user with the User Administrator role assigned.
.PARAMETER DimeSchedulerPassword
Password for the specified Dime.Scheduler user administrator
.EXAMPLE
New-Dime.SchedulerUser -DisplayName "Name of the user" -EmailAddress "user@email.com" -Language nl -TimeZone "Europe/Amsterdam" -DimeSchedulerUrl https://myurl
.OUTPUTS
System.Management.Automation.PSObject
.FUNCTIONALITY
Adds a new user to Dime.Scheduler using a REST API call.
#>
param
(
[parameter(Mandatory=$true, Position=0)][string]$DisplayName,
[parameter(Mandatory=$true, Position=1)][string]$EmailAddress,
[parameter(Mandatory=$false)][string]$Language = "nl",
[parameter(Mandatory=$false)][string]$TimeZone = "Europe/Amsterdam",
[parameter(Mandatory=$false)][string]$DimeSchedulerUrl,
[parameter(Mandatory=$false)][string]$DimeSchedulerUserName,
[parameter(Mandatory=$false)][string]$DimeSchedulerPassword
)
if([string]::IsNullOrEmpty($DimeSchedulerUrl))
{
$DimeSchedulerUrl = "https://url"
}
if([string]::IsNullOrEmpty($DimeSchedulerUserName))
{
$DimeSchedulerUserName = "formsuser"
$DimeSchedulerPassword = "password"
}
$hostName = $DimeSchedulerUrl.Replace("https://","")
#"content-length"="70";
$headers = @{
"cache-control"="no-cache";
"accept-encoding"="gzip,deflate";
"Host"="$($hostName)";
"Postman-Token"="062cdb02-aac8-4a9f-9c96-b451ee38afe7,192dc92a-0fc1-46b9-aa49-7a7a949b0c18";
"User-Agent"="PostmanRuntime/7.11.0";
"Accept"="application/json";
"Content-Type"="application/x-www-form-urlencoded";
}
$body="grant_type=password&username=$DimeSchedulerUserName&password=$DimeSchedulerPassword&="
$token = Invoke-RestMethod -Method Post -Uri "$($DimeSchedulerUrl)/Token" -Headers $headers -Body $body -DisableKeepAlive:$false
$dimeUserObj = New-Object PSObject
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "LoginId" -Value ""
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "Windows" -Value ""
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "CanSafelyDelete" -Value "true"
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "HasNoSharedProfiles" -Value "true"
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "HasNoSharedLayouts" -Value "true"
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "HasNoSharedFilters" -Value "true"
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "Id" -Value 1
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "Name" -Value $DisplayName
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "Type" -Value 1
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "Email" -Value $EmailAddress
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "Language" -Value $Language
$dimeUserObj | Add-Member -MemberType NoteProperty -Name "TimeZone" -Value $TimeZone
$req = $dimeUserObj | ConvertTo-Json
$apiRequestUri = "$($DimeSchedulerUrl)/api/Administration/Users/Create"
$headers = @{Authorization="Bearer $($token.access_token)"}
$response = Invoke-RestMethod -Uri $apiRequestUri -Method Post -Body $req -ContentType "application/json" -Headers $headers
Write-Output $response
}
Export-ModuleMember -Function New-DimeSchedulerUser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment