Overview
Are you tired of constantly trekking back and forth to your build bench, waiting to see when your devices will finish imaging? I was too. That's why I developed a script for our support team that captures the build results from our task sequence and automates those notifications, making the process more efficient and less time-consuming. I have been using this approach for some time now, but I figured it's worth sharing for those that are interest, so let's jump into it.
The Details
While you can include various items in your report, my main focus was on Make and Model, OS, OS Version, Serial Number, BIOS Version, Run Time, and Built By. The "Built By" field is customized to our environment and requires additional configuration. If you're interested in this setup, please feel free to reach out. Once I identified the necessary data for reporting, I created the PowerShell script below and added it to the task sequence. This will output the information into a txt file and stored onto a file share.
With the details of the built endpoint, you need a method to deliver that information. My solution was to create a PowerShell script that runs every 15 minutes via a scheduled task and reports on all endpoints built within the last 15 minutes. The script gathers the contents of files within the shared folder and converts them into JSON. From here, you have various options to deliver the build information into Teams. Initially, I used a Connector (WebHook specifically) for this, but since Microsoft announced the deprecation of connectors within Teams, we have since moved the workflow into Microsoft Power Automate. I will cover the details of the flow in another post, providing a detailed breakdown of the process within Power Automate and how that gets published into a Teams channel. A simple way to provide better visibility and awareness to your build teams.
PowerShell Code for Task Sequence
$Time = Get-Date -Format 'MMMdd_HHMMtt' $Name = (Get-WmiObject Win32_OperatingSystem).CSName $Make = (Get-WmiObject Win32_Bios).Manufacturer $Model = (Get-WmiObject Win32_ComputerSystem).Model $OSName = (Get-WmiObject Win32_OperatingSystem).Caption $OSVersion = (Get-WmiObject Win32_OperatingSystem).Version $BIOS_Serial = (Get-WmiObject Win32_Bios).SerialNumber $BIOS_Version = (Get-WmiObject Win32_Bios).SMBIOSBIOSVersion $Start_Time = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\MPSD\OSD" -Name OSDStartTime -ErrorAction SilentlyContinue $End_Time = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\MPSD\OSD" -Name OSDEndTime -ErrorAction SilentlyContinue $Run_Time = (NEW-TIMESPAN -Start $Start_Time -End $End_Time -ErrorAction SilentlyContinue).ToString('hh\hmm\mss\s') $OSDUserAuth = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\MPSD\OSD" -Name OSDUserAuth -ErrorAction SilentlyContinue Out-File -FilePath "\\FilesShare\BuildResults\$($Name)_$($Time).txt" -InputObject $Name, $Make, $Model, $OSName, $OSVersion, $BIOS_Serial, $BIOS_Version, $Run_Time, $OSDUserAuth -ErrorAction SilentlyContinue
$List = Get-ChildItem -Path \\FileShare\BuildResults -Recurse $URI = "https://example.com/example" If ($List.Count -ne 0) { ############################# ## BUILD RESULTS DISCOVERY ## ############################# $Table = @() ForEach ($Computer in $List) ## Filter Through Files { $DeviceInfo = Get-Content -Path $Computer.FullName $item = New-Object PSObject $item | Add-Member -type NoteProperty -Name 'Computer Name' -Value $($DeviceInfo)[0] $item | Add-Member -type NoteProperty -Name 'Make and Model' -Value $($DeviceInfo)[2] $item | Add-Member -type NoteProperty -Name 'Operating System' -Value $($DeviceInfo)[3] $item | Add-Member -type NoteProperty -Name 'OS Version' -Value $($DeviceInfo)[4] $item | Add-Member -type NoteProperty -Name 'Serial Number' -Value $($DeviceInfo)[5] $item | Add-Member -type NoteProperty -Name 'BIOS Version' -Value $($DeviceInfo)[6] $item | Add-Member -type NoteProperty -Name 'Run Time' -Value $($DeviceInfo)[7] $item | Add-Member -type NoteProperty -Name 'Built By' -Value $($DeviceInfo)[8] $Table += $item } $Header = @" <style> TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;} TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;} TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;} </style> "@ $Body = $Table | ConvertTo-Html $JSON_Multiple = $Table | ForEach { "$_<br>" } ################## ## JSON SECTION ## ################## If ($List.Count -eq 1) { $DeviceInfo_Json = Get-Content -Path $List.FullName $HostName = $($DeviceInfo_Json)[0] $MakeModel = $($DeviceInfo_Json)[2] $OS = $($DeviceInfo_Json)[3] $OSVersion = $($DeviceInfo_Json)[4] $SN = $($DeviceInfo_Json)[5] $BIOS = $($DeviceInfo_Json)[6] $RunTime = $($DeviceInfo_Json)[7] $BuiltBy = $($DeviceInfo_Json)[8] $json_body = ConvertTo-Json -Depth 4 @{ title = "OSD Build Results - Within Last 15 Minutes" themeColor = "ff1717" text = " " sections = @( @{ activityTitle = 'OSD Complete' activitySubtitle = "$HostName" activityImage = $logo }, @{ title = 'Detailed Information' facts = @( @{ name = 'Make and Model' value = "$MakeModel" }, @{ name = 'Operating System' value = "$OS" }, @{ name = 'OS Version' value = "$OSVersion" }, @{ name = 'Serial Number' value = "$SN" }, @{ name = 'BIOS Version' value = "$BIOS" }, @{ name = 'Run Time' value = "$RunTime" }, @{ name = 'Built By' value = "$BuiltBy" } ) } ) } } Else { ## Multiple Devices } ########################### ## Send to PowerAutomate ## ########################### If ($List.Count -eq 1) { Invoke-RestMethod -uri $URI -Method Post -body $json_body -ContentType 'application/json' -ErrorAction SilentlyContinue } Else { Invoke-RestMethod -uri $URI -Method Post -body "{'title': 'OSD Build Results - Within Last 15 Minutes', 'activityTitle': 'OSD Complete', 'themeColor': 'ff1717', 'text': '$Body'}" -ContentType 'application/json' -ErrorAction SilentlyContinue } ##################### ## Cleanup Actions ## ##################### If ($List.Count -eq 1) { Remove-Item -Path $List.FullName -Force } Else { ForEach ($File in $List) { Remove-Item -Path $File.FullName -Force } } } Else { ## Bypass Sending Report }
0 Comments