HornbillUserAddGroup.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

<#PSScriptInfo
 
.VERSION 1.1.2
 
.GUID f0d886e9-d349-4a28-aa33-d5773088949d
 
.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
 
.DESCRIPTION
 Azure Automation Runbook to add a user to a group 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 userId
#MANDATORY: ID of the user being added to the group

#.PARAMETER groupId
#MANDATORY: ID of the group

#.PARAMETER memberRole
#MANDATORY: Role the user will take in the group (member, teamLeader or manager)

#.PARAMETER tasksView
#If set true, then the user can view tasks assigned to this group

#.PARAMETER tasksAction
#If set true, then the user can action tasks assigned to this group.

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

workflow Hornbill_UserAddGroup_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] $userId,
        [Parameter (Mandatory= $true)]
        [string] $groupId,
        [Parameter (Mandatory= $true)]
        [string] $memberRole,
        [boolean] $tasksView,
        [boolean] $tasksAction
    )
    # Define instance details
    Set-HB-Instance -Instance $instanceName -Key $instanceKey

    # Build XMLMC Call
    Add-HB-Param "userId" $userId $false
    Add-HB-Param "groupId" $groupId $false
    Add-HB-Param "memberRole" $memberRole $false
    if($tasksView -eq $true -or $tasksAction -eq $true){
        Open-HB-Element "options"
        if($tasksView -eq $true){
            Add-HB-Param "tasksView" "true"
        }
        if($tasksAction -eq $true){
            Add-HB-Param "tasksAction" "true"
        }
        Close-HB-Element "options"
    }

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

    # 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
    }
}