-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewServiceRequest.ps1
87 lines (80 loc) · 2.81 KB
/
NewServiceRequest.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
param(
[ValidateSet("Request Machine")]
[string]$Type = "Request Machine",
[ValidateSet("Small", "Medium", "Large")]
[string]$Size = "Small",
[string]$User
)
Import-Module "$Repository\Modules\ServiceCatalog\1.0.0\ServiceCatalog.psd1"
$Connection = Connect-Database
try
{
$queryParameters = @{
Title = $Type
Description = "Requesting a VM of size $size"
Requester = $User
Manager = "adam@ironmansoftware.onmicrosoft.com"
Status = 0
}
Invoke-DbaQuery -Query "INSERT INTO dbo.ServiceRequests (Title, Description, Requester, Status, Manager) VALUES (@Title, @Description, @Requester, @Status, @Manager)" -SqlInstance $Connection -SqlParameter $queryParameters | Out-Null
$RequestId = Invoke-DbaQuery -Query "SELECT Id FROM dbo.ServiceRequests WHERE Requester = @Requester AND Status = 0" -SqlInstance $Connection -SqlParameter $queryParameters | Select-Object -First 1
}
finally
{
$Connection | Disconnect-DbaInstance | Out-Null
}
$Message = @{
summary = "$User is requesting a virtual machine of size $size."
"@type" = "MessageCard"
"@context" = "http://schema.org/extensions"
"themeColor" = "0076D7"
"sections" = @(
@{
"activityTitle" = "$User is request a virtual machine of size $size."
"activitySubtitle" = "Do you approve?"
"facts" = @(
@{
"name" = "Requester"
"value" = $User
}
@{
"name" = "Size"
"value" = $Size
}
)
"markdown" = $true
}
)
"potentialAction" = @(
@{
"@type" = "ActionCard"
"name" = "Approve"
"inputs" = @(
@{
"@type" = "MultichoiceInput"
"id" = "Status"
"title" = "Do you approve?"
"isMultiSelect" = "false"
"choices" = @(
@{
"display" = "Approved"
"value" = "1"
}
@{
"display" = "Denied"
"value" = "2"
}
)
}
)
"actions" = @(
@{
"@type" = "HttpPOST"
"name" = "Update"
"target" = "https://psdaych-1.azurewebsites.net/request/$($RequestId.Id)"
}
)
}
)
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Method post -ContentType 'Application/Json' -Body $Message -Uri $Secret:TeamsWebHook