LumifyTrainerTools.psm1
function Submit-ClassRoll { <# .SYNOPSIS Converts DDLS student list into web output .DESCRIPTION Extract the list of students from the Teams trainer portal as a CSV file. Once this has been done you can then run this script which will ask you for attendance for each student and produce a report that you can paste into an email sent to Training. This script also has the ability to print an intoduction list that allows you to write down information about each of the students as they introduce themselves, it also gives you the ability to print a list of labs that you can tick off as the class members finish their labs. .EXAMPLE Submit-ClassRoll -CsvFileName students.csv -TrainerName 'Brent Denny' -PathToFiles 'c:\class' This will ask for confirmation for each students attendance on the course and then produce a report which we need to email to training. .EXAMPLE Submit-ClassRoll -CsvFileName students.csv -StudentIntro -PathToFiles 'c:\class' This will produce a report that allows writing space beside each students name to record the info from their introduction. .EXAMPLE Submit-ClassRoll -CsvFileName students.csv -LabList -NumberOfLabs 12 -PathToFiles 'c:\class' This will produce a report showing a list of lab number next to each student so that you can track which labs they have finished in the course. .EXAMPLE Submit-ClassRoll -CsvFileName students.csv -ShowAllDetails This lists all of the student details on screen and does nothing else, this is not compatible with any other parameters other than CsvFileName. .PARAMETER CsvFileName This points to the file path of the CSV file that we export from the Teams trainer portal. .PARAMETER TrainerName This is the name of the trainer that gets added to the attendance report so that when we paste this into the body of the email, we can then cut the "Attendance BRENT DENNY" from the body and this into the mail subject, as required. .PARAMETER StudentIntro This will create a report to record the introduction information from the students as they talk about themselves. .PARAMETER LabList This will create a report that will list lab numbers per student that we can tick off as they finish each lab. .PARAMETER NumberOfLabs This will give you the ability to specify how many lab numbers show on the web page, the default is 18, this was chosen as it would cover most courses, not many courses exceed 18 labs. .PARAMETER PathToFiles This is the path to find the CSV file and where this script will create the reports to be opened by the systems default browser, this is the folder path not the file names, the default path points to your current Downloads directory. .PARAMETER ShowAllDetails This lists all of the student details on screen and does nothing else, this is not compatible with any other parameters other than CsvFileName. .NOTES General notes Created By: Brent Denny Created On: 19 Jan 2021 Last Change: 5 Apr 2021 #> [CmdletBinding(DefaultParameterSetName='DefaultParams')] Param( [Parameter(Mandatory=$true)] [string]$CsvFileName, [string]$TrainerName = 'Brent Denny', [switch]$StudentIntro, [switch]$LabList, [int]$NumberOfLabs = 18, [string]$PathToFiles = ((New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path), [switch]$ShowAllDetails ) # Extracting failename from $CsvFileName $CsvFileName = $CsvFileName | Split-Path -leaf # Setup file paths $CsvFullPath = $PathToFiles.TrimEnd('\') + '\' + $CsvFileName if (Test-Path -Path $CsvFullPath -PathType Leaf) { $AttendanceReportPath = $PathToFiles.TrimEnd('\') + '\ClassAttendance.html' $LabListReportPath = $PathToFiles.TrimEnd('\') + '\ClassLabList.html' $IntroReportPath = $PathToFiles.TrimEnd('\') + '\ClassIntro.html' $UpCaseTrainer = $TrainerName.ToUpper() # Locate the default browser on the computer $DefaultSettingPath = 'HKCU:\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice' $DefaultBrowserName = (Get-Item $DefaultSettingPath | Get-ItemProperty).ProgId $DefaultBrowserOpenCommand = (Get-Item "HKLM:SOFTWARE\Classes\$DefaultBrowserName\shell\open\command" | Get-ItemProperty).'(default)' $DefaultBrowserPath = [regex]::Match($DefaultBrowserOpenCommand,'\".+?\"') $BrowserPath = $DefaultBrowserPath.Value # Getting student details into a PowerShell object $RawStudentListCsv = Get-Content $CsvFullPath # Remove any non-student entries and removing spaces from CSV property names $RemoveSpacesFromCsvTitles = (($RawStudentListCSV | Select-Object -First 1) -replace '(\s)|(\(.*?\)|\-)','' ) -split ',' $RawStudentListCsvNoTitle = $RawStudentListCsv | Select-Object -Skip 1 $StudentListCSVtoObj = $RawStudentListCsvNoTitle | ConvertFrom-Csv -Header $RemoveSpacesFromCsvTitles | Sort-Object -Property StudentName if ($ShowAllDetails -eq $true) { return $StudentListCSVtoObj } $StudentCount = $StudentListCSVtoObj.Count # Calculating how much space for padding to fit all students one one page if ($StudentCount -gt 12) {$Padding = 40} else {$Padding = 200 - (12.5 * $StudentCount) } # Setting up the CSS for the web output $CSSsmall = @" <style> table, tr,td,th {border:black 1pt solid;border-collapse:collapse;} td,th {padding-left:4pt;padding-right:4px;} td:nth-child(1) {width: auto;} td:nth-child(2) {width: auto;} </style> "@ $CSSwide = @" <style> table, tr,td,th {border:black 1pt solid;border-collapse:collapse;} td,th {padding-left:4pt;padding-right:4px;} td {padding-bottom: ${Padding}px;} td:nth-child(1) {width: 20%;} td:nth-child(2) {text-align-last: justify;font-size:20px} table {width: 100%} </style> "@ if ($LabList -eq $false -and $StudentIntro -eq $false) { #Check for attendance $StudentsWithAttendance = foreach ($Student in $StudentListCSVtoObj) { $AttendanceResult = Read-Host -Prompt "Is $($Student.StudentName) in attendance (Y or N) Default-Y" if ($AttendanceResult -eq '' -or $AttendanceResult -like 'y*') { $Student | Select-Object -Property *,@{n='InClass';e={'Y'}} } else { $Student | Select-Object -Property *,@{n='InClass';e={'N'}} } } try { $StudentsWithAttendance | Select-Object -Property StudentName,InClass | ConvertTo-Html -Head $CSSsmall -precontent "<h2>Attendance $UpCaseTrainer</h2> <br>" | Out-File $AttendanceReportPath Start-Process -FilePath $BrowserPath -ArgumentList $AttendanceReportPath } catch {Write-Warning "The Attendance html document could not be written to disk"; break} } if ($LabList -eq $true) { $StudentsLabNumbers = $StudentListCSVtoObj | Select-Object *, @{n='LabNumbers';e={(1..$NumberOfLabs) -join ' '}} try { $StudentsLabNumbers | Select-Object -Property StudentName,LabNumbers | ConvertTo-Html -Head $CSSwide | Out-File $LabListReportPath Start-Process -FilePath $BrowserPath -ArgumentList $LabListReportPath } catch {Write-Warning "The Lablist html document could not be written to disk"; break} } if ($StudentIntro -eq $true) { try { write-debug "intro" $StudentListCSVtoObj | Select-Object -Property StudentName,Intro | ConvertTo-Html -Head $CSSwide | Out-File $IntroReportPath Start-Process -FilePath $BrowserPath -ArgumentList $IntroReportPath } catch {Write-Warning "The Intro html document could not be written to disk"; break} } } else { Write-Warning "The CSV file path $CsvFullPath is not found" } } function Invoke-ClassTimer { <# .Synopsis Calculates the end of break times in multiple cities and shows a countdown timer .DESCRIPTION This program calclates event end times for Brisbane, Melbourne/Sydney, Adelaide Perth, Auckland and the USA Pacific TZ by default. Determining when each city should end the event they are undertaking break/lab, relevant to their timezone. You can enter the "Event Length" in minutes time and then click "Calculate End Time" and it will automatically determine when each city's end time should be. It will also start a countdown timer in color stages Green for > 2 min left, Orange for 0 >= time left >= 2, and Red for time is up! .EXAMPLE Invoke-ClassTimer This will start a gui tool to determine end of break times .NOTES General notes Created By: Brent Denny Created On: 28 May 2020 Change Log: 14Sep21: Changing the timer to be a general time and not just for breaks Cleand up the help and disabled Melbourne in the GUI 24Aug22: Rewrote the entire command to be able to run form anywhere using UTC time values. also added color coding as the timer runs out, added each city as a combo box so that all of the cities can be changed. 25Aug22: Modified the count down timer to refresh the window every second. 12Dec22: Modified the colors of the countdown box and set the value back to actual minutes left. 13Sep23 This has been completely re-written to show seconds as well as minutes the code is also streamlined and much easier to understand. #> [cmdletbinding()] Param () $Script:TimeZones = Get-TimeZone -ListAvailable $UTCDateTime = [System.DateTime]::UtcNow function Get-FinishTime { Param ( $fnUtcTime = [System.DateTime]::UtcNow, [Parameter(mandatory=$true)] [timespan]$Offset, [int]$fnSetTime = 0 ) if ($fnUtcTime -is [datetime]) { $TimespanFromSettime = New-TimeSpan -Minutes $fnSetTime $EndTimeObj = [datetime]($fnUtcTime + $Offset + $TimespanFromSettime) $FormattedResult = $EndTimeObj.ToShortTimeString() + ' ' + ($EndTimeObj.DayOfWeek).ToString() return [PSCustomObject]@{ FormattedResult = $FormattedResult EndTimeObj = $EndTimeObj } } } Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() $formLumifyTimer = New-Object system.Windows.Forms.Form $formLumifyTimer.ClientSize = New-Object System.Drawing.Point(578,708) $formLumifyTimer.text = "Lumify Class Timer" $formLumifyTimer.TopMost = $false $Groupbox1 = New-Object system.Windows.Forms.Groupbox $Groupbox1.height = 237 $Groupbox1.width = 240 $Groupbox1.location = New-Object System.Drawing.Point(12,14) $Groupbox2 = New-Object system.Windows.Forms.Groupbox $Groupbox2.height = 234 $Groupbox2.width = 277 $Groupbox2.location = New-Object System.Drawing.Point(267,14) $Groupbox3 = New-Object system.Windows.Forms.Groupbox $Groupbox3.height = 335 $Groupbox3.width = 536 $Groupbox3.location = New-Object System.Drawing.Point(9,266) $butReset = New-Object system.Windows.Forms.Button $butReset.text = "Reset" $butReset.width = 60 $butReset.height = 30 $butReset.location = New-Object System.Drawing.Point(389,633) $butReset.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $butReset.Enabled = $false $butClose = New-Object system.Windows.Forms.Button $butClose.text = "Close" $butClose.width = 60 $butClose.height = 30 $butClose.location = New-Object System.Drawing.Point(476,633) $butClose.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $labSetTime = New-Object system.Windows.Forms.Label $labSetTime.text = "Set Time" $labSetTime.AutoSize = $true $labSetTime.width = 25 $labSetTime.height = 10 $labSetTime.location = New-Object System.Drawing.Point(28,70) $labSetTime.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',13) $tboxSetTime = New-Object system.Windows.Forms.TextBox $tboxSetTime.multiline = $false $tboxSetTime.width = 71 $tboxSetTime.height = 20 $tboxSetTime.location = New-Object System.Drawing.Point(115,63) $tboxSetTime.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',17) $tboxSetTime.Text = 15 $butStartTimer = New-Object system.Windows.Forms.Button $butStartTimer.text = "Start Timer" $butStartTimer.width = 100 $butStartTimer.height = 39 $butStartTimer.location = New-Object System.Drawing.Point(116,156) $butStartTimer.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $Script:tboxTimeRemaining = New-Object system.Windows.Forms.TextBox $Script:tboxTimeRemaining.multiline = $false $Script:tboxTimeRemaining.width = 190 $Script:tboxTimeRemaining.height = 20 $Script:tboxTimeRemaining.location = New-Object System.Drawing.Point(39,77) $Script:tboxTimeRemaining.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',50) $Script:tboxTimeRemaining.TextAlign = 'Right' $LabTimeRemaining = New-Object system.Windows.Forms.Label $LabTimeRemaining.text = "Time Remaining" $LabTimeRemaining.AutoSize = $true $LabTimeRemaining.width = 25 $LabTimeRemaining.height = 10 $LabTimeRemaining.location = New-Object System.Drawing.Point(38,52) $LabTimeRemaining.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ1 = New-Object system.Windows.Forms.ComboBox $cboxTZ1.width = 311 $cboxTZ1.height = 29 $cboxTZ1.location = New-Object System.Drawing.Point(37,46) $cboxTZ1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ1.Items.AddRange($Script:TimeZones) $cboxTZ1.DisplayMember = 'DisplayName' $cboxTZ1.ValueMember = 'Id' $cboxTZ1.SelectedItem = $Script:TimeZones | Where-Object {$_.DisplayName -match 'Brisbane'} $cboxTZ2 = New-Object system.Windows.Forms.ComboBox $cboxTZ2.width = 311 $cboxTZ2.height = 29 $cboxTZ2.location = New-Object System.Drawing.Point(37,86) $cboxTZ2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ2.Items.AddRange($Script:TimeZones) $cboxTZ2.DisplayMember = 'DisplayName' $cboxTZ2.ValueMember = 'Id' $cboxTZ2.SelectedItem = $Script:TimeZones | Where-Object {$_.DisplayName -match 'Sydney'} $cboxTZ3 = New-Object system.Windows.Forms.ComboBox $cboxTZ3.width = 311 $cboxTZ3.height = 29 $cboxTZ3.location = New-Object System.Drawing.Point(37,126) $cboxTZ3.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ3.Items.AddRange($Script:TimeZones) $cboxTZ3.DisplayMember = 'DisplayName' $cboxTZ3.ValueMember = 'Id' $cboxTZ3.SelectedItem = $Script:TimeZones | Where-Object {$_.DisplayName -match 'Adelaide'} $cboxTZ4 = New-Object system.Windows.Forms.ComboBox $cboxTZ4.width = 311 $cboxTZ4.height = 29 $cboxTZ4.location = New-Object System.Drawing.Point(37,166) $cboxTZ4.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ4.Items.AddRange($Script:TimeZones) $cboxTZ4.DisplayMember = 'DisplayName' $cboxTZ4.ValueMember = 'Id' $cboxTZ4.SelectedItem = $Script:TimeZones | Where-Object {$_.DisplayName -match 'Perth'} $cboxTZ5 = New-Object system.Windows.Forms.ComboBox $cboxTZ5.width = 311 $cboxTZ5.height = 29 $cboxTZ5.location = New-Object System.Drawing.Point(37,206) $cboxTZ5.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ5.Items.AddRange($Script:TimeZones) $cboxTZ5.DisplayMember = 'DisplayName' $cboxTZ5.ValueMember = 'Id' $cboxTZ5.SelectedItem = $Script:TimeZones | Where-Object {$_.DisplayName -match 'Tokyo'} $cboxTZ6 = New-Object system.Windows.Forms.ComboBox $cboxTZ6.width = 311 $cboxTZ6.height = 29 $cboxTZ6.location = New-Object System.Drawing.Point(37,246) $cboxTZ6.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12) $cboxTZ6.Items.AddRange($Script:TimeZones) $cboxTZ6.DisplayMember = 'DisplayName' $cboxTZ6.ValueMember = 'Id' $cboxTZ6.SelectedItem = $Script:TimeZones | Where-Object {$_.DisplayName -match 'Hawaii'} $labTZ1 = New-Object system.Windows.Forms.Label $labTZ1.text = (Get-FinishTime -fnUtcTime $Script:UTCDateTime -Offset $cboxTZ1.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ1.AutoSize = $true $labTZ1.width = 25 $labTZ1.height = 10 $labTZ1.location = New-Object System.Drawing.Point(355,50) $labTZ1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',11) $labTZ1.Visible = $false $labTZ2 = New-Object system.Windows.Forms.Label $labTZ2.text = (Get-FinishTime -fnUtcTime $Script:UTCDateTime -Offset $cboxTZ2.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ2.AutoSize = $true $labTZ2.width = 25 $labTZ2.height = 10 $labTZ2.location = New-Object System.Drawing.Point(355,90) $labTZ2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',11) $labTZ2.Visible = $false $labTZ3 = New-Object system.Windows.Forms.Label $labTZ3.text = (Get-FinishTime -fnUtcTime $Script:UTCDateTime -Offset $cboxTZ3.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ3.AutoSize = $true $labTZ3.width = 25 $labTZ3.height = 10 $labTZ3.location = New-Object System.Drawing.Point(355,130) $labTZ3.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',11) $labTZ3.Visible = $false $labTZ4 = New-Object system.Windows.Forms.Label $labTZ4.text = (Get-FinishTime -fnUtcTime $Script:UTCDateTime -Offset $cboxTZ4.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ4.AutoSize = $true $labTZ4.width = 25 $labTZ4.height = 10 $labTZ4.location = New-Object System.Drawing.Point(355,170) $labTZ4.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',11) $labTZ4.Visible = $false $labTZ5 = New-Object system.Windows.Forms.Label $labTZ5.text = (Get-FinishTime -fnUtcTime $Script:UTCDateTime -Offset $cboxTZ5.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ5.AutoSize = $true $labTZ5.width = 25 $labTZ5.height = 10 $labTZ5.location = New-Object System.Drawing.Point(355,210) $labTZ5.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',11) $labTZ5.Visible = $false $labTZ6 = New-Object system.Windows.Forms.Label $labTZ6.text = (Get-FinishTime -fnUtcTime $Script:UTCDateTime -Offset $cboxTZ6.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ6.AutoSize = $true $labTZ6.width = 25 $labTZ6.height = 10 $labTZ6.location = New-Object System.Drawing.Point(355,250) $labTZ6.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',11) $labTZ6.Visible = $false $formLumifyTimer.controls.AddRange(@($Groupbox1,$Groupbox2,$Groupbox3,$butReset,$butClose)) $Groupbox1.controls.AddRange(@($labSetTime,$tboxSetTime,$butStartTimer)) $Groupbox2.controls.AddRange(@($tboxTimeRemaining,$LabTimeRemaining)) $Groupbox3.controls.AddRange(@($cboxTZ1,$cboxTZ6,$cboxTZ2,$cboxTZ3,$cboxTZ4,$cboxTZ5,$labTZ1,$labTZ2,$labTZ3,$labTZ4,$labTZ5,$labTZ6)) $butStartTimer.Add_Click({ $butStartTimer.Enabled = $false if ($Script:Timer) { $Script:Timer.Stop() $Script:Timer.Dispose() } $butReset.Enabled = $true $EndTime = (Get-FinishTime -Offset ([timespan]::New(0)) -fnSetTime ($tboxSetTime.Text -as [int])).EndTimeObj $labTZ1.text = (Get-FinishTime -Offset $cboxTZ1.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ2.text = (Get-FinishTime -Offset $cboxTZ2.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ3.text = (Get-FinishTime -Offset $cboxTZ3.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ4.text = (Get-FinishTime -Offset $cboxTZ4.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ5.text = (Get-FinishTime -Offset $cboxTZ5.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ6.text = (Get-FinishTime -Offset $cboxTZ6.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int])).FormattedResult $labTZ1.Visible = $true $labTZ2.Visible = $true $labTZ3.Visible = $true $labTZ4.Visible = $true $labTZ5.Visible = $true $labTZ6.Visible = $true $cboxTZ1.Enabled = $false $cboxTZ2.Enabled = $false $cboxTZ3.Enabled = $false $cboxTZ4.Enabled = $false $cboxTZ5.Enabled = $false $cboxTZ6.Enabled = $false $Script:EndTime = (Get-Date).AddMinutes(($tboxSetTime.text -as [int])) $Script:Timer = New-Object System.Windows.Forms.Timer $Script:Timer.Interval = 1000 $Script:Timer.Add_Tick({ $Remaining = $Script:EndTime - (Get-Date) $TotalMinutes = [int]($Remaining.Hours * 60) + $Remaining.Minutes if ($Remaining.Seconds -lt 10) {$Filler = '0'} else {$Filler = ''} if ($TotalMinutes -gt 2) {$Groupbox2.BackColor = 'Green'} elseif ($TotalMinutes -gt 1) {$Groupbox2.BackColor = 'Orange'} elseif ($TotalMinutes -ge 0 -and $Remaining.TotalSeconds -ge 0) {$Groupbox2.BackColor = 'Red'} else { $Script:Timer.stop() $Script:Timer.Dispose() } $DisplayedTimeRemaining = '' + $TotalMinutes + ':' + $Filler +$Remaining.Seconds $Script:tboxTimeRemaining.Text = $DisplayedTimeRemaining }) $Script:Timer.Start() }) $butReset.Add_Click({ $butStartTimer.Enabled = $true $butReset.Enabled = $false $labTZ1.text = '' $labTZ2.text = '' $labTZ3.text = '' $labTZ4.text = '' $labTZ5.text = '' $labTZ6.text = '' $labTZ1.Visible = $true $labTZ2.Visible = $true $labTZ3.Visible = $true $labTZ4.Visible = $true $labTZ5.Visible = $true $labTZ6.Visible = $true $tboxSetTime.Text = 15 $tboxTimeRemaining.Text = '' $cboxTZ1.Enabled = $true $cboxTZ2.Enabled = $true $cboxTZ3.Enabled = $true $cboxTZ4.Enabled = $true $cboxTZ5.Enabled = $true $cboxTZ6.Enabled = $true $Groupbox2.BackColor = '' $Script:Timer.Dispose() $Script:Timer.Stop() }) $butClose.Add_Click({ $butStartTimer.Enabled = $true $butReset.Enabled = $false $labTZ1.text = '' $labTZ2.text = '' $labTZ3.text = '' $labTZ4.text = '' $labTZ5.text = '' $labTZ6.text = '' $labTZ1.Visible = $true $labTZ2.Visible = $true $labTZ3.Visible = $true $labTZ4.Visible = $true $labTZ5.Visible = $true $labTZ6.Visible = $true $tboxSetTime.Text = 15 $tboxTimeRemaining.Text = '' $cboxTZ1.Enabled = $true $cboxTZ2.Enabled = $true $cboxTZ3.Enabled = $true $cboxTZ4.Enabled = $true $cboxTZ5.Enabled = $true $cboxTZ6.Enabled = $true $Script:Timer.Dispose() $Script:Timer.Stop() $Groupbox2.BackColor = '' $formLumifyTimer.Close() $formLumifyTimer.Dispose() }) $cboxTZ1.Add_SelectedValueChanged({ $labTZ1.text = Get-FinishTime -Offset $cboxTZ1.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int]) }) $cboxTZ2.Add_SelectedValueChanged({ $labTZ2.text = Get-FinishTime -Offset $cboxTZ2.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int]) }) $cboxTZ3.Add_SelectedValueChanged({ $labTZ3.text = Get-FinishTime -Offset $cboxTZ3.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int]) }) $cboxTZ4.Add_SelectedValueChanged({ $labTZ4.text = Get-FinishTime -Offset $cboxTZ4.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int]) }) $cboxTZ5.Add_SelectedValueChanged({ $labTZ5.text = Get-FinishTime -Offset $cboxTZ5.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int]) }) $cboxTZ6.Add_SelectedValueChanged({ $labTZ6.text = Get-FinishTime -Offset $cboxTZ6.SelectedItem.BaseUtcOffset -fnSetTime ($tboxSetTime.Text -as [int]) }) #region Logic #endregion [void]$formLumifyTimer.ShowDialog() } Function New-MyDDLSClassListIntro { <# .SYNOPSIS Takes the XLSX file from My DDLS classlist and converts it to CSV and HTML files .DESCRIPTION The My DDLS classlist for trainers can be downloaded as an Excel spreadsheet file. This script takes that xlsx file and converts it into an html file ready for printing it has the student's name and a box for notes when running the intro. It also calculates how many students are on the course and creates the table column height high enough to fit a class of 1 - 13 on the same page. .EXAMPLE New-MyDDLSClassListIntro This expects to find a class list downloaded into the downloads directory, if there are several it chooses the most recent file to convert, it then uses the filename to produce csv and html files in the same directory .EXAMPLE New-MyDDLSClassListIntro -ClassRollFile c:\Demo\ClassList.xlsx This locates the class list from the demo directory, it then uses the filename to produce csv and html files in the same directory .PARAMETER ClassRollFile This is the path to, and including the name of the classlist excel file .NOTES General notes Created By: Brent Denny Created On: 20-Apr-2022 Last Modified: 20-Apr-2022 ChangeLog Version Date Details ------- ---- ------- v0.1.0 20-Apr-2022 Created, this converts xlsx DDLS class roll files into csv and html files v0.1.1 02-May-2022 Fixed the Excel discovery issue #> Param ( [string]$ClassRollFile = ((Get-ChildItem ~\downloads\portal_class*.xlsx | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1).FullName) ) $ExcelAppReg = (Get-ChildItem HKLM:\Software\Classes).Name | Where-Object {$_ -like '*Excel.Application'} if ($ExcelAppReg.Count -eq 0) { Write-Warning "Excel needs to be installed on your computer before running this script" break } $ExcelObj = New-Object -ComObject Excel.Application $ExcelObj.Visible = $false $ExcelObj.DisplayAlerts = $false $WorkBook = $ExcelObj.Workbooks.Open($ClassRollFile) $FileLocation = (Split-Path $ClassRollFile -Parent).TrimEnd('\') + '\' $FileName = Split-Path $ClassRollFile -Leaf foreach ($WorkSheet in $WorkBook.Worksheets) { $CSVName = $FileLocation + $FileName + "_" + $WorkSheet.Name + '.csv' $HtmlName = $FileLocation + $FileName + "_" + $WorkSheet.Name + '.html' $WorkSheet.SaveAs($CSVName, 6) $CsvObj = Import-Csv -Path $CSVName $StudentCount = $CsvObj.count $RowHeight = [math]::Round(900/$StudentCount,0) $CSS = @" <style> table {border:solid 2pt black;border-collapse:collapse;width:100%;} th,tr {border:solid 2pt black;border-collapse:collapse;} td {border:solid 2pt black;border-collapse:collapse;height:${RowHeight}px;} </style> "@ $RawHtml = $CsvObj | Sort-Object -Property Student | Select-Object Student,Notes | ConvertTo-Html -Head $CSS $RawHtml -replace '\<th\>Student\<\/th\>','<th style=width:200px;>Student</th>' | Out-File $HtmlName } $ExcelObj.Quit() } function New-LumifyClassList { <# .Synopsis Lumify classlist exported from the Instructor Portal show as html .DESCRIPTION This command will take a CSV file exported from the Instructor Portal and convert it into a HTML document and launch the browser or it will show the information on screen in a table. The Csv data is obtained by going to the "Trainer Portal" in MS Teams, left-click within the area where the student info is found, choose the ellipsis (More Options) and then choose "Export Data" than "Summarized Data" and finally choose the file format as CSV and Click the Export button. .EXAMPLE New-LumifyClassList -CourseTitle 'AZ104' This will look for the data.csv file (by default) in the downloads folder of the currently loggedon user, it will then convert it to a timestamped csv filename and will create a timstamped html document that will show in Chrome browser that can be easily printed to show who is on the course. These files are created in the same directory that the original csv was found in. .EXAMPLE New-LumifyClassList -ExportedFilePath e:\data1.csv -NoHtml -CourseTitle 'AZ104' This will look for a data1.csv file in the e:\ drive and will then show the details on screen. .PARAMETER ExportedFilePath This is the path to the exported csv file. This includes that path and the filename of the CSV exported file. .PARAMETER CourseTitle The course title will be presented above the HTML table, it is a mandatory parameter .PARAMETER NoHtml This will prevent this command creating a HTML document but will instead display the details about the attendees in a table on the screen. More information is shown on the screen than would be shown as the html output. .PARAMETER ShowPersonalDetails This will show the basic information and the email address and phone number for each student. Without this parameter the phone number and email address will not be shown. .INPUTS String CSV .OUTPUTS file HTML .NOTES General notes Created by: Brent Denny Change Notes Version When What ------- ---- ---- 1.0 15-May-2023 finished the script initial code 2.0 06-Jun-2023 Changed to height and alignment of the <TR> so that 12 students fit on one page 3.0 06-Jul-2023 Saves the original file with a timestamp filename, opens the browser if using html 4.0 05-Sep-2023 Rewritten to make the code simpler to read and understand also added updates to help 5.0 08-Sep-2023 Changed the output to have a course title and sorting of students by Location and then name If nohtml is used it does not rename the file, and if original data file not found it searches for the last one that was accessed. #> [CmdletBinding(DefaultParameterSetName='Html')] Param( [string]$ExportedFilePath = $env:HOMEDRIVE + $env:HOMEPATH + '\downloads\data.csv', [Parameter(Mandatory=$true)] [string]$CourseTitle, [Parameter(ParameterSetName = 'Html')] [switch]$ShowPersonalDetails, [Parameter(ParameterSetName = 'NoHtml')] [switch]$NoHtml ) # Check to see if the exported file exisits if (-not (Test-Path -Path $ExportedFilePath)) { $ExportedFileDir = ($ExportedFilePath | Split-Path).TrimEnd('\') $PreviousDataFiles = Get-ChildItem -Path $ExportedFileDir | Where-Object {$_.Name -like 'StudentList-*.csv'} | Sort-Object -Property LastAccessTime -Descending $ExportedFilePath = ($PreviousDataFiles | Select-Object -First 1 ).FullName } if (Test-Path -Path $ExportedFilePath){ # Check to see if the Exported file can be imported if ($ExportedFilePath -match 'csv$') { $Css = '<style>h1 {text-align:center} table {border:1px solid black;border-collapse:collapse;width:100%;} th {border:1px solid black;border-collapse:collapse;text-align:center;} tr {text-align:left;vertical-align:top;border:1px solid black;border-collapse:collapse;height:75px;vertical-align:top;} tr:first-child {vertical-align:left;height:40px;}</style>' $ExportedFileDir = ($ExportedFilePath | Split-Path).TrimEnd('\') $NewHtmlFilePath = $ExportedFileDir + '\' + (Get-Date -UFormat 'StudentList-%Y%m%d%H%M%S.html') $NewCsvFilePath = $ExportedFileDir + '\' + (Get-Date -UFormat 'StudentList-%Y%m%d%H%M%S.csv') try { if ($NoHtml -eq $false) { Rename-Item -Path $ExportedFilePath -NewName $NewCsvFilePath -Force -ErrorAction Stop } else { $NewCsvFilePath = $ExportedFilePath } } catch {Write-Warning "$ExportedFilePath was not able to be renamed"; break} $ExportedDataObj = Get-Content -Path $NewCsvFilePath | ConvertFrom-Csv -Header 'StudentName','Company','Phone','Email','TrainingSite','State','Code1','Code2','LabCode','LabPassword','AccountManager' | Select-Object -Skip 1 -Property 'StudentName', 'Company', 'Phone', 'Email', 'TrainingSite', 'State', 'Code1', 'Code2', 'LabCode', 'LabPassword', 'AccountManager' | Sort-Object -Property TrainingSite,StudentName if ($ShowPersonalDetails -eq $true) {$StudentInfo = $ExportedDataObj | Select-Object -Property StudentName,Company,TrainingSite,Email} else {$StudentInfo = $ExportedDataObj | Select-Object -Property StudentName,Company,TrainingSite,AccountManager,State} if ($NoHtml) { Clear-Host $ExportedDataObj | Select-Object -Property StudentName,Company,TrainingSite,Email,Phone,AccountManager | Format-Table } else { try { $StudentInfo | ConvertTo-Html -Head $Css -PreContent "<h1>Course Title: $CourseTitle</h1>" | Out-File -FilePath $NewHtmlFilePath -ErrorAction Stop } catch {Write-Warning "Could not save $NewHtmlFilePath file "; break} & "C:\Program Files\Google\Chrome\Application\chrome.exe" $NewHtmlFilePath } } else { Write-Warning "$ExportedFilePath is not in a CSV format please re-export the file from the Teams Instructor Portal again" break } } else { Write-Warning "$ExportedFilePath is not found" break } } |