HornbillUserCreate.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

<#PSScriptInfo
 
.VERSION 1.1.1
 
.GUID 89e1b09f-94e7-448b-8f86-b6211fbfaab2
 
.AUTHOR steve.goldthorpe@hornbill.com
 
.COMPANYNAME Hornbill
 
.TAGS hornbill powershell azure automation workflow runbook
 
.LICENSEURI https://wiki.hornbill.com/index.php/The_Hornbill_Community_License_(HCL)
 
.PROJECTURI https://github.com/hornbill/powershellHornbillAzureRunbooks
 
.ICONURI https://wiki.hornbill.com/skins/common/images/HBLOGO.png
 
.RELEASENOTES
Corrected metadata
Included parameter descriptions
 
.DESCRIPTION
 Azure Automation Runbook to create a user on a Hornbill instance.
 
#>


#.PARAMETER instanceName
#MANDATORY: The name of the Instance to connect to.

#.PARAMETER instanceKey
#MANDATORY: An API key with permission on the Instance to carry out the required API calls.

#.PARAMETER newId
#MANDATORY: The ID of the new user

#.PARAMETER name
#MANDATORY: The users fullname (handle)

#.PARAMETER newPwd
#MANDATORY: The users password

#.PARAMETER userType
#The type of user (basic or user)

#.PARAMETER firstName
#The users firstname

#.PARAMETER lastName
#The users surname

#.PARAMETER jobTitle
#The users job title

#.PARAMETER siteName
#The users site name

#.PARAMETER phone
#The users phone number

#.PARAMETER email
#The users email address

#.PARAMETER mobile
#The users mobile or secondary phone number

#.PARAMETER availabilityStatus
#The users availability status

#.PARAMETER absenceMessage
#The users current absence message

#.PARAMETER timeZone
#The users timezone (taken from the instance default if not specified)

#.PARAMETER language
#The users language (taken from the instance default if not specified)

#.PARAMETER dateTimeFormat
#The users preferred datetime format (taken from the instance default if not specified)

#.PARAMETER dateFormat
#The users preferred date format (taken from the instance default if not specified)

#.PARAMETER timeFormat
#The users preferred time format (taken from the instance default if not specified)

#.PARAMETER currencySymbol
#The users local currency symbol (taken from the instance default if not specified)

#.PARAMETER countryCode
#The users country code (taken from the instance default if not specified)

#Requires -Module @{ModuleName = 'HornbillAPI'; ModuleVersion = '1.1.0'}
#Requires -Module @{ModuleName = 'HornbillHelpers'; ModuleVersion = '1.1.1'}

workflow Hornbill_UserCreate_Workflow
{
    #Define Output Stream Type
    [OutputType([object])]

    # Define runbook input params
    Param
    (
        # Instance connection params
        [Parameter (Mandatory= $true)]
        [string] $instanceName,
        [Parameter (Mandatory= $true)]
        [string] $instanceKey,

        # API Params
        [Parameter (Mandatory= $true)]
        [string] $newId,
        [Parameter (Mandatory= $true)]
        [string] $name,
        [Parameter (Mandatory= $true)]
        [string] $newPwd,
        [string] $userType,
        [string] $firstName,
        [string] $lastName,
        [string] $jobTitle,
        [string] $siteName,
        [string] $phone,
        [string] $email,
        [string] $mobile,
        [string] $availabilityStatus,
        [string] $absenceMessage,
        [string] $timeZone,
        [string] $language,
        [string] $dateTimeFormat,
        [string] $dateFormat,
        [string] $timeFormat,
        [string] $currencySymbol,
        [string] $countryCode
    )

    # Define instance details
    Set-HB-Instance -Instance $instanceName -Key $instanceKey

    # Base64 encode password string
    $pwdb64 = ConvertTo-HB-B64Encode $newPwd

    # Get SiteID from Name
    $siteId = ""
    if($siteName -and $siteName -ne "") {
        $siteObj = Get-HB-SiteID $siteName
        $siteId = $siteObj.SiteID
    }

    Add-HB-Param "userId" $newId $false
    Add-HB-Param "name" $name $false
    Add-HB-Param "password" $pwdb64 $false
    Add-HB-Param "userType" $userType $false
    Add-HB-Param "firstName" $firstName $false
    Add-HB-Param "lastName" $lastName $false
    Add-HB-Param "jobTitle" $jobTitle $false
    Add-HB-Param "site" $siteId $false
    Add-HB-Param "phone" $phone $false
    Add-HB-Param "email" $email $false
    Add-HB-Param "mobile" $mobile $false
    Add-HB-Param "availabilityStatus" $availabilityStatus $false
    Add-HB-Param "absenceMessage" $absenceMessage $false
    Add-HB-Param "timeZone" $timeZone $false
    Add-HB-Param "language" $language $false
    Add-HB-Param "dateTimeFormat" $dateTimeFormat $false
    Add-HB-Param "dateFormat" $dateFormat $false
    Add-HB-Param "timeFormat" $timeFormat $false
    Add-HB-Param "currencySymbol" $currencySymbol $false
    Add-HB-Param "countryCode" $countryCode $false

    # Invoke XMLMC call, output returned as PSObject
    $xmlmcOutput = Invoke-HB-XMLMC "admin" "userCreate"

    # Build resultObject to write to output
    $resultObject = New-Object PSObject -Property @{
        Status = $xmlmcOutput.status
        Error = $xmlmcOutput.error
    }

    if($resultObject.Status -ne "ok"){
        Write-Error $resultObject
    } else {
        Write-Output $resultObject
    }
}