1
+ <#
2
+ . SYNOPSIS
3
+ Gets the SQLBits Schedule from the Sessionize API
4
+
5
+ . DESCRIPTION
6
+ Gets the SQLBits Schedule from the Sessionize API and outputs to json, excel, psobject, html or csv
7
+
8
+ . PARAMETER Output
9
+ The type of output required. Valid values are json, excel, psobject, html or csv
10
+
11
+ . PARAMETER fileDirectory
12
+ The directory to save the output file to - defaults to Env:Temp
13
+
14
+ . PARAMETER Show
15
+ Whether to open the output file after it has been created
16
+
17
+ . EXAMPLE
18
+ Get-SQLBitsSchedule -Output Excel -Show
19
+
20
+ Gets the SQLBits Schedule from the Sessionize API and outputs to excel, opens the file and saves it to the default temp directory
21
+
22
+ . EXAMPLE
23
+ Get-SQLBitsSchedule -Output Raw
24
+
25
+ Gets the SQLBits Schedule from the Sessionize API and outputs as json on the screen
26
+
27
+ . EXAMPLE
28
+ Get-SQLBitsSchedule -Output csv -Show
29
+
30
+ Gets the SQLBits Schedule from the Sessionize API and outputs to csv, opens the file and saves it to the default temp directory
31
+
32
+ . EXAMPLE
33
+ Get-SQLBitsSchedule -Output object
34
+
35
+ Gets the SQLBits Schedule from the Sessionize API and outputs as a psobject on the screen
36
+
37
+ . EXAMPLE
38
+ Get-SQLBitsSchedule -Output html -Show
39
+
40
+ Gets the SQLBits Schedule from the Sessionize API and outputs to html, opens the file and saves it to the default temp directory
41
+
42
+ . NOTES
43
+ Author: Rob Sewell
44
+ December 2022
45
+ #>
1
46
function Get-SQLBitsSchedule {
2
47
[CmdletBinding ()]
3
48
param (
4
- # [Parameter()]
5
- # [ValidateSet('All', 'Schedule', 'Sessions', 'Speakers')]
6
- # $filter = 'Schedule',
7
- # # How do you want it?
8
49
[Parameter ()]
9
- [ValidateSet (' Raw' , ' Excel' )]
10
- $Output = ' Raw'
50
+ [ValidateSet (' raw' , ' excel' , ' object' , ' csv' , ' html' )]
51
+ $Output = ' excel' ,
52
+ [string ]
53
+ $fileDirectory = $env: TEMP ,
54
+ [switch ]
55
+ $Show
11
56
)
12
57
13
58
$BaseUri = ' https://sessionize.com/api/v2/u1qovn3p/view'
59
+ $Date = Get-Date - Format ' yyyy-MM-dd-HH-mm-ss'
60
+
61
+ # TODO Add other opttions
14
62
$filter = ' Schedule'
15
63
switch ($filter ) {
16
64
' All' {
@@ -30,101 +78,104 @@ function Get-SQLBitsSchedule {
30
78
}
31
79
}
32
80
33
- $Data = Invoke-RestMethod - Uri $uri
81
+ $Data = Invoke-RestMethod - Uri $uri
82
+ $rooms = ($data.rooms | Sort-Object name)
83
+ $Speakers = $data.speakers
84
+ # Thank you Shane - https://nocolumnname.blog/2020/10/29/pivot-in-powershell/
85
+ $props = @ (
86
+ @ { Name = ' Day' ; Expression = { $Psitem.Group [0 ].startsAt.DayOfWeek } }
87
+ @ { Name = ' Date' ; Expression = { $Psitem.Group [0 ].startsAt.tolongdatestring() } }
88
+ @ { Name = ' StartTime' ; Expression = { $Psitem.Group [0 ].startsAt.ToShortTimeString() } }
89
+ @ { Name = ' EndTime' ; Expression = { $Psitem.Group [0 ].EndsAt.ToShortTimeString() } }
90
+ foreach ($room in $rooms ) {
91
+ $rn = $room.Name
92
+ @ {
93
+ Name = $rn
94
+ Expression = {
95
+ ' {0}
96
+ {1}' -f @ (
97
+ ($Psitem.Group | Where-Object { $PSItem.roomID -eq $room.id }).title,
98
+ (($Psitem.Group | Where-Object { $PSItem.roomID -eq $room.id }).Speakers.ForEach{ $Speakers | Where-Object id -EQ $_ }.FullName -join ' ' )
99
+ )
100
+
101
+ }.GetNewClosure()
102
+ }
103
+ }
104
+ )
105
+
106
+ $sessions = $Data.sessions | Group-Object - Property StartsAt | Select-Object $props
34
107
35
108
switch ($output ) {
36
- ' Raw' {
109
+ ' Raw' {
37
110
$Data
38
111
}
39
- ' Excel' {
112
+ ' object' {
113
+ $sessions
114
+ }
115
+ ' Excel' {
40
116
if (Get-Module - Name ImportExcel - ErrorAction SilentlyContinue - ListAvailable) {
41
117
if ($filter -eq ' Schedule' ) {
42
- $rooms = ($data.rooms | Sort-Object name)
43
- $Speakers = $data.speakers
44
- # Thank you Shane - https://nocolumnname.blog/2020/10/29/pivot-in-powershell/
45
- $props = @ (
46
- @ { Name = ' Day' ; Expression = { $Psitem.Group [0 ].startsAt.DayOfWeek } }
47
- @ { Name = ' Date' ; Expression = { $Psitem.Group [0 ].startsAt.tolongdatestring() } }
48
- @ { Name = ' StartTime' ; Expression = { $Psitem.Group [0 ].startsAt.ToShortTimeString() } }
49
- @ { Name = ' EndTime' ; Expression = { $Psitem.Group [0 ].EndsAt.ToShortTimeString() } }
50
- foreach ($room in $rooms ) {
51
- $rn = $room.Name
52
- @ {
53
- Name = $rn
54
- Expression = {
55
- ' {0}
56
- {1}' -f @ (
57
- ($Psitem.Group | Where-Object { $PSItem.roomID -eq $room.id }).title,
58
- (($Psitem.Group | Where-Object { $PSItem.roomID -eq $room.id }).Speakers.ForEach{ $Speakers | Where-Object id -eq $_ }.FullName -join ' ' )
59
- )
60
-
61
- }.GetNewClosure()
62
- }
63
- }
64
- )
65
- $Date = Get-Date - Format ' yyyy-MM-dd-HH-mm-ss'
66
- $FilePath = ' {0}\SQLBitsSchedule{1}_{2}.xlsx' -f $env: TEMP , $filter , $Date
67
-
68
- $sessions = $Data.sessions | Group-Object - Property StartsAt | Select-Object $props
69
118
70
- $sessions | Group-Object Day | ForEach-Object {
71
-
119
+ $FilePath = ' {0}\SQLBitsSchedule{1}_{2}.xlsx' -f $fileDirectory , $filter , $Date
120
+
121
+ $sessions | Group-Object Day | ForEach-Object {
122
+
72
123
$worksheetName = $_.Name
73
- $excel = $_.Group | Export-Excel - Path $FilePath - WorksheetName $worksheetName - AutoSize - FreezePane 2 , 5 - PassThru
74
- 1 .. 15 | ForEach-Object {
75
- Set-ExcelRow - ExcelPackage $excel - WorksheetName $worksheetName - Row $_ - Height 30 - WrapText
76
- }
77
-
78
-
124
+ $excel = $_.Group | Export-Excel - Path $FilePath - WorksheetName $worksheetName - AutoSize - FreezePane 2 , 5 - PassThru
125
+ 1 .. 15 | ForEach-Object {
126
+ Set-ExcelRow - ExcelPackage $excel - WorksheetName $worksheetName - Row $_ - Height 30 - WrapText
127
+ }
128
+
79
129
$rulesparam = @ {
80
130
Address = $excel.Workbook.Worksheets [$WorkSheetName ].Dimension.Address
81
- WorkSheet = $excel.Workbook.Worksheets [$WorkSheetName ]
82
- RuleType = ' Expression'
131
+ WorkSheet = $excel.Workbook.Worksheets [$WorkSheetName ]
83
132
}
133
+
134
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Coffee Break",$E1)))' - BackgroundColor GoldenRod - ForegroundColor White - StopIfTrue
135
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Quick Break",$E1)))' - BackgroundColor GoldenRod - ForegroundColor White - StopIfTrue
136
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Keynote",$E1)))' - BackgroundColor BlueViolet - ForegroundColor White - StopIfTrue
137
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Lunch",$E1)))' - BackgroundColor Chocolate - ForegroundColor White - StopIfTrue
138
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Prize",$E1)))' - BackgroundColor PowderBlue - ForegroundColor White - StopIfTrue
139
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Free Time",$E1)))' - BackgroundColor GoldenRod - ForegroundColor White - StopIfTrue
140
+ Add-ConditionalFormatting @rulesparam - RuleType ' Expression' - ConditionValue ' NOT(ISERROR(FIND("Registration",$E1)))' - BackgroundColor DarkOrange - ForegroundColor White - StopIfTrue
84
141
85
- Add-ConditionalFormatting @rulesparam - ConditionValue ' "Break",$E1)))' - BackgroundColor PaleGreen - StopIfTrue
86
- Add-ConditionalFormatting @rulesparam - ConditionValue ' NOT(ISERROR(FIND("Keynote",$E1)))' - BackgroundColor BlueViolet - StopIfTrue
87
- Add-ConditionalFormatting @rulesparam - ConditionValue ' NOT(ISERROR(FIND("Lunch",$E1)))' - BackgroundColor Chocolate
88
- Add-ConditionalFormatting @rulesparam - ConditionValue ' NOT(ISERROR(FIND("Prize",$E1)))' - BackgroundColor PowderBlue
89
- Add-ConditionalFormatting @rulesparam - ConditionValue ' NOT(ISERROR(FIND("Free",$E1)))' - BackgroundColor GoldenRod
90
- Add-ConditionalFormatting @rulesparam - ConditionValue ' NOT(ISERROR(FIND("Registration",$E1)))' - BackgroundColor DarkOrange
91
-
92
- Close-ExcelPackage $excel
93
- }
94
- Invoke-Item $filepath
142
+ Close-ExcelPackage $excel
143
+ }
144
+ if ($Show ) {
145
+ Invoke-Item $filepath
146
+ }
95
147
}
96
-
97
148
} else {
98
149
Write-Warning ' You need to install ImportExcel to use this option but here is a CSV instead'
99
- $Data | Export-Csv - Path .\SQLBitsSchedule.csv - NoTypeInformation
150
+ $FilePath = ' {0}\SQLBits_{1}_{2}.csv' -f $fileDirectory , $filter , $Date
151
+ $sessions | Sort-Object Day, StartsAt | Export-Csv - Path $FilePath - NoTypeInformation
152
+ if ($Show ) {
153
+ Invoke-Item $filepath
154
+ }
100
155
}
101
156
102
157
}
158
+ ' CSv' {
159
+ $FilePath = ' {0}\SQLBits_{1}_{2}.csv' -f $fileDirectory , $filter , $Date
160
+ $sessions | Sort-Object Day, StartsAt | Export-Csv - Path $FilePath - NoTypeInformation
161
+ if ($Show ) {
162
+ Invoke-Item $filepath
163
+ }
164
+ }
165
+ ' html' {
166
+ $FilePath = ' {0}\SQLBits_{1}_{2}.html' -f $fileDirectory , $filter , $Date
167
+ $sessions | ConvertTo-Html | out-file $FilePath
168
+ if ($Show ) {
169
+ Invoke-Item $filepath
170
+ }
171
+ }
103
172
Default {
104
173
105
174
}
106
175
}
107
176
}
108
- Get-SQLBitsSchedule - Output Excel
109
- <#
110
- foreach ($day in $data[2]){
111
- $Date = '{0} {1}' -f $day.date.DayOfWeek, $day.date.ToLongDateString()
112
- $Schedule = ''
113
-
114
- }
115
-
116
- ($data.sessions | Group-Object startsat)[0]
117
- v
118
-
119
-
120
- $SortedSessions = foreach ($time in ($data.sessions | Group-Object startsat).Group){
121
- $room = $data.rooms.where{$PsItem.id -eq $time.roomid}.name
122
- [PSCustomObject]@{
123
- startsat = $time.startsat
124
- endsat = $time.endsat
125
-
126
- $room = $time.title
127
- }
128
- }
129
- $SortedSessions | Export-Excel -Path c:\temp\sess.xlsx -Show
130
- #>
177
+ # Get-SQLBitsSchedule -Output Excel -Show
178
+ # Get-SQLBitsSchedule -Output Raw
179
+ # Get-SQLBitsSchedule -Output csv -Show
180
+ # Get-SQLBitsSchedule -Output object
181
+ # Get-SQLBitsSchedule -Output html -Show
0 commit comments