Functions/Applications/Add-PASApplication.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
function Add-PASApplication {
    <#
.SYNOPSIS
Adds a new application to the Vault

.DESCRIPTION
Adds a new application to the Vault.
Manage Users permission is required.

.PARAMETER AppID
The application name.
Must be fewer than 128 characters.
Cannot include ampersand ("&") character.
Can include "@" character, but any searches for applications cannot include
this character.

.PARAMETER Description
Description of the application, no longer than 99 characters.

.PARAMETER Location
The location of the application in the vault hierarchy.
Note: to insert a backslash in the location path, use a double backslash.

.PARAMETER AccessPermittedFrom
The start hour that access is permitted to the application.
Valid values are 0-23.

.PARAMETER AccessPermittedTo
The end hour that access to the application is permitted.
Valid values are 0-23.

.PARAMETER ExpirationDate
The date when the application expires.

.PARAMETER Disabled
Boolean value, denoting if the application is disabled or not.

.PARAMETER BusinessOwnerFName
The first name of the business owner.
Specify up to 29 characters.

.PARAMETER BusinessOwnerLName
The last name of the business owner.

.PARAMETER BusinessOwnerEmail
The email address of the business owner

.PARAMETER BusinessOwnerPhone
The phone number of the business owner.
Specify up to 24 characters.

.EXAMPLE
Add-PASApplication -AppID NewApp -Description "A new application" -Location "\" `
-AccessPermittedFrom 9 -AccessPermittedTo 17 -BusinessOwnerEmail 'appowner@company.com'

Will add a new application called "NewApp", in the root location, accessible from 9am to 5pm

.INPUTS
All parameters can be piped by property name


.LINK
https://pspas.pspete.dev/commands/Add-PASApplication
#>

    [CmdletBinding()]
    param(
        [parameter(
            Mandatory = $true,
            ValueFromPipelinebyPropertyName = $true
        )]
        [ValidateNotNullOrEmpty()]
        [ValidateLength(1, 127)]
        [ValidateScript( { $_ -notmatch ".*(\&).*" })]
        [string]$AppID,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [ValidateLength(0, 99)]
        [string]$Description,

        [parameter(
            Mandatory = $true,
            ValueFromPipelinebyPropertyName = $true
        )]
        [string]$Location,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [ValidateRange(0, 23)]
        [int]$AccessPermittedFrom,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [ValidateRange(0, 23)]
        [int]$AccessPermittedTo,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [datetime]$ExpirationDate,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [boolean]$Disabled,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [ValidateLength(0, 29)]
        [string]$BusinessOwnerFName,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [string]$BusinessOwnerLName,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [string]$BusinessOwnerEmail,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [ValidateLength(0, 24)]
        [string]$BusinessOwnerPhone

    )

    BEGIN { }#begin

    PROCESS {

        #WebService URL
        $URI = "$Script:BaseURI/WebServices/PIMServices.svc/Applications"

        #Get request parameters
        $boundParameters = $PSBoundParameters | Get-PASParameter

        If ($PSBoundParameters.ContainsKey("ExpirationDate")) {

            #Convert ExpiryDate to string in Required format
            $Date = (Get-Date $ExpirationDate -Format MM-dd-yyyy).ToString()

            #Include date string in request
            $boundParameters["ExpirationDate"] = $Date

        }

        #Create Request Body
        $body = @{

            "application" = $boundParameters

        } | ConvertTo-Json

        #Send Request
        Invoke-PASRestMethod -Uri $URI -Method POST -Body $Body -WebSession $Script:WebSession

    }#process

    END { }#end
}