<# .SYNOPSIS Collect OS & HW information and send to Teams channel .DESCRIPTION http://osdgather.homburger.osdcloud.ch .NOTES Version: 0.3 Creation Date: 01.11.2024 Author: Ákos Bakos Company: SmartCon GmbH Contact: akos.bakos@smartcon.ch Copyright (c) 2024 SmartCon GmbH HISTORY: Date By Comments ---------- --- ---------------------------------------------------------- 01.11.2024 Ákos Bakos Added helper functions 11.11.2024 Ákos Bakos Added new workflow connector 02.12.2024 Ákos Bakos Removed SpeedTest part 02.12.2024 Ákos Bakos Added OSDCloud + Autopilot information 04.12.2024 Ákos Bakos Added new workflow connector für Homburger 17.03.2025 Ákos Bakos Added new adaptive card format 08.09.2025 Ákos Bakos Updated Teams webhook URL 13.04.2026 Ákos Bakos $OSDCloudTimeCompleted now shows "Unavailable" if time is not available instead of "0 hour(s) 0 minutes 0 seconds" 16.04.2026 Ákos Bakos Switched OSDCloud time calculation to MME-style: uses $JSON.TimeStart.DateTime and Get-Date as end reference (measures from deploy start to gathering run). #> #region Helper Functions function Write-DarkGrayDate { [CmdletBinding()] param ( [Parameter(Position=0)] [System.String] $Message ) if ($Message) { Write-Host -ForegroundColor DarkGray "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) $Message" } else { Write-Host -ForegroundColor DarkGray "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) " -NoNewline } } function Write-DarkGrayHost { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [System.String] $Message ) Write-Host -ForegroundColor DarkGray $Message } function Write-DarkGrayLine { [CmdletBinding()] param () Write-Host -ForegroundColor DarkGray "=========================================================================" } function Write-SectionHeader { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [System.String] $Message ) Write-DarkGrayLine Write-DarkGrayDate Write-Host -ForegroundColor Cyan $Message } function Write-SectionSuccess { [CmdletBinding()] param ( [Parameter(Position=0)] [System.String] $Message = 'Success!' ) Write-DarkGrayDate Write-Host -ForegroundColor Green $Message } #endregion $Title = "OSD Gathering" $host.UI.RawUI.WindowTitle = $Title [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials $env:APPDATA = "C:\Windows\System32\Config\SystemProfile\AppData\Roaming" $env:LOCALAPPDATA = "C:\Windows\System32\Config\SystemProfile\AppData\Local" $Env:PSModulePath = $env:PSModulePath+";C:\Program Files\WindowsPowerShell\Scripts" $env:Path = $env:Path+";C:\Program Files\WindowsPowerShell\Scripts" $Global:Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-OSD-Gathering.log" Start-Transcript -Path (Join-Path "$env:ProgramData\Microsoft\IntuneManagementExtension\Logs\OSD\" $Global:Transcript) -ErrorAction Ignore | Out-Null Write-SectionHeader "Importing OSD Module" $module = Import-Module OSD -PassThru -ErrorAction Ignore if (-not $module) { Write-Host "Installing OSD module" Install-Module OSD -Force | Out-Null } Import-Module OSD -Force | Out-Null $OSDGathering = Get-OSDGather -Full $OSDGatheringJSON = Get-OSDGather -Full | ConvertTo-Json $OSDGatheringJSON #region measure WinPE & OSDCloud time completed $JsonPath = "C:\OSDCloud\Logs\OSDCloud.json" if (Test-Path $JsonPath){ $JSON= Get-Content -Path $JsonPath -Raw | ConvertFrom-Json $WinPECompleted = "$($JSON.TimeSpan.Minutes) minutes $($JSON.TimeSpan.Seconds) seconds" $WinPECompleted $OSDEnd = Get-Date $OSDCouldTime = New-TimeSpan -Start $JSON.TimeStart.DateTime -End $OSDEnd $OSDCouldTime $OSDCouldTimeCompleted = "$($OSDCouldTime.Hours) hour(s) $($OSDCouldTime.Minutes) minutes $($OSDCouldTime.Seconds) seconds" $OSDCouldTimeCompleted $GetFeatureUpdateReleaseDate = $Json.GetFeatureUpdate.ReleaseDate $GetFeatureUpdateName = $Json.GetFeatureUpdate.Name } #endregion #region collect Autopilot information $JsonPath = "C:\ProgramData\OSDeploy\OSDeploy.AutopilotOOBE.json" if (Test-Path $JsonPath){ $JSON= Get-Content -Path $JsonPath -Raw | ConvertFrom-Json $AutopilotAssignedComputerName = $Json.AssignedComputerName $AutopilotAddToGroup = $Json.AddToGroup } #endregion Write-SectionHeader "Collecting OSD Information" $ComputerName = $OSDGathering.OperatingSystem.CSName $ComputerModel = $OSDGathering.ComputerSystemProduct.Name $OS = $OSDGathering.OperatingSystem.Caption $OSVersion = $OSDGathering.RegVersion.LCUVer $BuildNumber = $OSDGathering.ComputerInfo.OSDisplayVersion $BiosSerialNumber = $OSDGathering.BIOS.SerialNumber $BiosVersion = $OSDGathering.BIOS.SMBIOSBIOSVersion $BiosReleaseDate = $OSDGathering.BIOS.ReleaseDate $OSDCloudVersion = (Get-Module -Name OSD -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString() $IPAddress = (Get-WmiObject win32_Networkadapterconfiguration | Where-Object{ $_.ipaddress -notlike $null }).IPaddress | Select-Object -First 1 $Connection = Get-NetAdapter -physical | Where-Object status -eq 'up' $ConnectionName = $connection.Name $ConnectionDescription = $connection.InterfaceDescription Write-SectionHeader "Sending OSD Information to Teams" $TeamsMessage = @{ type = "message" attachments = @( @{ contentType = "application/vnd.microsoft.card.adaptive" content = @{ type = "AdaptiveCard" version = "1.3" body = @( @{ type = "TextBlock" text = "OSD Information - Homburger" weight = "Bolder" size = "Large" }, @{ type = "TextBlock" text = "The following client has been successfully deployed:" size = "Medium" wrap = $true }, @{ "type" = "TextBlock" "text" = "Computer Information" "weight" = "Bolder" "wrap" = $true "icon" = @{ "url" = "https://adaptivecards.io/content/computer.png" } }, @{ type = "FactSet" facts = @( @{ title = "Computer Name:"; value = "$ComputerName" }, @{ title = "Model:"; value = "$ComputerModel" }, @{ title = "OS Version:"; value = "$OS $OSVersion" }, @{ title = "Build Number:"; value = "$BuildNumber" }, @{ title = "ESD File Release Date:"; value = "$GetFeatureUpdateReleaseDate" }, @{ title = "ESD File Name:"; value = "$GetFeatureUpdateName" }, @{ title = "BIOS Serial Number:"; value = "$BiosSerialNumber" }, @{ title = "BIOS Version:"; value = "$BiosVersion" }, @{ title = "BIOS Release Date:"; value = "$BiosReleaseDate" }, @{ title = "Connection Type:"; value = "$ConnectionName" }, @{ title = "IP Address:"; value = "$IPAddress" }, @{ title = "Connection Description:"; value = "$ConnectionDescription" } ) }, @{ "type" = "TextBlock" "text" = " " "spacing" = "Medium" }, @{ type = "TextBlock" text = "Autopilot Information" weight = "Bolder" size = "Medium" wrap = $true "iconUrl" = "https://adaptivecards.io/content/settings.png" }, @{ type = "FactSet" facts = @( @{ title = "Computer Name:"; value = "$AutopilotAssignedComputerName" }, @{ title = "Group Name:"; value = "$AutopilotAddToGroup" } ) }, @{ "type" = "TextBlock" "text" = " " "spacing" = "Medium" }, @{ type = "TextBlock" text = "Deployment Information" weight = "Bolder" size = "Medium" wrap = $true "iconUrl" = "https://adaptivecards.io/content/lightbulb.png" }, @{ type = "FactSet" facts = @( @{ title = "OSDCloud Version:"; value = "$OSDCloudVersion" }, @{ title = "WinPE Time Completed:"; value = "$WinPECompleted" }, @{ title = "OSDCloud Time Completed:"; value = "$OSDCouldTimeCompleted" } ) } ) } } ) } | ConvertTo-JSON -Depth 10 #$URISmartCon = 'https://prod-57.westeurope.logic.azure.com:443/workflows/65ebd5cc044e48379c3caeee5b0dc943/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=TPRJcGaJjNyqZaapCwm7qN2wFUWIcMq4mkNCX_JW0hE' $URISmartCon ='https://default48b608715f614b52ab7bcfbcf6137f.61.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/65ebd5cc044e48379c3caeee5b0dc943/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=e736p-g-zthwvjpvzC5w691Qw2Vf1AXjOKtpN42m90g' Invoke-RestMethod -Uri $URISmartCon -Method Post -ContentType "application/json" -Body $TeamsMessage $URIHomburger ='https://prod-03.switzerlandnorth.logic.azure.com:443/workflows/3a092a236b6b4c98afe0375953634844/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=n12Y0uD6yO_7Vg58jSHeOudH1Y4VnmDmWmDmy6skXX8' Invoke-RestMethod -Uri $URIHomburger -Method Post -ContentType "application/json" -Body $TeamsMessage Stop-Transcript | Out-Null