└── Gather.ps1 /Gather.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Name: Gather.ps1 3 | Actual version: 1.0.7 4 | Author: Johan Schrewelius, Onevinn AB 5 | Date: 2018-10-17 v. 1.0.0 6 | Command: powershell.exe -executionpolicy bypass -file Gather.ps1 [-debug] 7 | Usage: Run in SCCM Task Sequence as lightweight replacement for MDT Gather Step 8 | Remark: Creates and sets a limited number of MDT Task Sequence variables, the most commonly used - subjectiveley 9 | Updated by Sassan Fanai, Onevinn: Added switch parameter and logic to handle Lenovo models. 10 | 2018-12-24 v. 1.0.1: Added more variables and debug switch, aligned variable names with MDT. 11 | 2019-01-09 v. 1.0.2: Protected OSDComputerName from being overwritten if already set. 12 | 2019-01-27 v. 1.0.3: Added method for checking bitlocker status and encryption method. 13 | 2020-04-13 v. 1.0.4: Additional variables when executed in Full OS: OsLocale, WindowsInstallationType, WindowsProductName, TimeZone. 14 | Added desktop chassis type "35". 15 | 2023-04-09 v. 1.0.5: Added variable 'SystemSKUNumber' (According to advice from Mike Terrill) 16 | 2023-11-21 - GARY BLOK - Added UBR for the OS on C:\ 17 | 2023-15-12 v. 1.0.7: Various bug fixes to prevent error during TS 18 | 2024-02-28 - GARY BLOK - Adding MachineMatchID - a unique idea used to match devices to driver packs #MMS2024 19 | #> 20 | 21 | param ( 22 | [switch]$UseOldLenovoName, 23 | [switch]$Debug 24 | ) 25 | 26 | $TSvars = @{} 27 | 28 | $DesktopChassisTypes = @("3","4","5","6","7","13","15","16","35") 29 | $LatopChassisTypes = @("8","9","10","11","12","14","18","21","30","31") 30 | $ServerChassisTypes = @("23") 31 | 32 | $VirtualHosts = @{ "Virtual Machine"="Hyper-V"; "VMware Virtual Platform"="VMware"; "VMware7,1"="VMware"; "VirtualBox"="VirtualBox"; "Xen"="Xen" } 33 | 34 | $EncryptionMethods = @{ 0 = "UNSPECIFIED"; 35 | 1 = 'AES_128_WITH_DIFFUSER'; 36 | 2 = "AES_256_WITH_DIFFUSER"; 37 | 3 = 'AES_128'; 38 | 4 = "AES_256"; 39 | 5 = 'HARDWARE_ENCRYPTION'; 40 | 6 = "XTS_AES_128"; 41 | 7 = "XTS_AES_256" } 42 | 43 | function Get-ComputerSystemProductInfo { 44 | 45 | $cmp = gwmi -Class 'Win32_ComputerSystemProduct' 46 | 47 | If ($cmp.Vendor -eq "LENOVO" -and $UseOldLenovoName -ne $true) { 48 | $tempModel = $cmp.Version 49 | } 50 | else { 51 | $tempModel = $cmp.Name 52 | } 53 | 54 | $TSvars.Add("Model", $tempModel) 55 | $TSvars.Add("UUID", $cmp.UUID) 56 | $TSvars.Add("Vendor", $cmp.Vendor) 57 | 58 | if($VirtualHosts.ContainsKey($tempModel)) { 59 | $TSvars.Add("IsVM", "True") 60 | $TSvars.Add("VMPlatform", $VirtualHosts[$tempModel]) 61 | } 62 | else { 63 | $TSvars.Add("IsVM", "False") 64 | $TSvars.Add("VMPlatform", "") 65 | } 66 | } 67 | 68 | function Get-ComputerSystemInfo { 69 | 70 | $cmp = gwmi -Class 'Win32_ComputerSystem' 71 | $TSvars.Add("Memory", ($cmp.TotalPhysicalMemory / 1024 / 1024).ToString()) 72 | if($cmp.SystemSKUNumber){ 73 | $TSvars.Add("SystemSKUNumber", $cmp.SystemSKUNumber) 74 | } 75 | } 76 | 77 | function Get-Product { 78 | 79 | $bb = gwmi -Class 'Win32_BaseBoard' 80 | $TSvars.Add("Product", $bb.Product) 81 | } 82 | 83 | function Get-BiosInfo { 84 | 85 | $bios = gwmi -Class 'Win32_BIOS' 86 | $TSvars.Add("SerialNumber", $bios.SerialNumber) 87 | $TSvars.Add("BIOSVersion", $bios.SMBIOSBIOSVersion) 88 | $TSvars.Add("BIOSReleaseDate", $bios.ReleaseDate) 89 | } 90 | 91 | function Get-OsInfo { 92 | 93 | $Os = gwmi -Class 'Win32_OperatingSystem' 94 | $TSvars.Add("OSCurrentVersion", $Os.Version) 95 | $TSvars.Add("OSCurrentBuild", $Os.BuildNumber) 96 | } 97 | 98 | function Get-SystemEnclosureInfo { 99 | 100 | $chassi = gwmi -Class 'Win32_SystemEnclosure' 101 | $TSvars.Add("AssetTag", $chassi.SMBIOSAssetTag) 102 | 103 | $chassi.ChassisTypes | foreach { 104 | 105 | if($TSvars.ContainsKey("IsDesktop")) { 106 | $TSvars["IsDesktop"] = [string]$DesktopChassisTypes.Contains($_.ToString()) 107 | } 108 | else { 109 | $TSvars.Add("IsDesktop", [string]$DesktopChassisTypes.Contains($_.ToString())) 110 | } 111 | 112 | if($TSvars.ContainsKey("IsLaptop")) { 113 | $TSvars["IsLaptop"] = [string]$LatopChassisTypes.Contains($_.ToString()) 114 | } 115 | else { 116 | $TSvars.Add("IsLaptop", [string]$LatopChassisTypes.Contains($_.ToString())) 117 | } 118 | 119 | if($TSvars.ContainsKey("IsServer")) { 120 | $TSvars["IsServer"] = [string]$ServerChassisTypes.Contains($_.ToString()) 121 | } 122 | else { 123 | $TSvars.Add("IsServer", [string]$ServerChassisTypes.Contains($_.ToString())) 124 | } 125 | } 126 | } 127 | 128 | function Get-NicConfigurationInfo { 129 | 130 | (gwmi -Class 'Win32_NetworkAdapterConfiguration' -Filter "IPEnabled = 1") | foreach { 131 | 132 | $_.IPAddress |% { 133 | if($_ -ne $null) { 134 | if($_.IndexOf('.') -gt 0 -and !$_.StartsWith("169.254") -and $_ -ne "0.0.0.0") { 135 | 136 | if($TSvars.ContainsKey("IPAddress")) { 137 | $TSvars["IPAddress"] = $TSvars["IPAddress"] + ',' + $_ 138 | } 139 | else { 140 | $TSvars.Add("IPAddress", $_) 141 | } 142 | } 143 | } 144 | } 145 | 146 | $_.DefaultIPGateway |% { 147 | 148 | if($_ -ne $null -and $_.IndexOf('.') -gt 0) { 149 | 150 | if($TSvars.ContainsKey("DefaultGateway")) { 151 | $TSvars["DefaultGateway"] = $TSvars["DefaultGateway"] + ',' + $_ 152 | } 153 | else { 154 | $TSvars.Add("DefaultGateway", $_) 155 | } 156 | } 157 | } 158 | } 159 | } 160 | 161 | function Get-MacInfo { 162 | 163 | $nic = (gwmi -Class 'Win32_NetworkAdapter' -Filter "NetConnectionStatus = 2") 164 | $TSvars.Add("MacAddress", $nic.MACAddress -join ',') 165 | } 166 | 167 | function Get-BatteryStatus { 168 | 169 | try { 170 | $AcConnected = (gwmi -Namespace 'root\wmi' -Query "SELECT * FROM BatteryStatus Where Voltage > 0" -EA SilentlyContinue).PowerOnline 171 | } 172 | catch { } 173 | 174 | if ($AcConnected -eq $null) { 175 | $AcConnected = "True" 176 | } 177 | 178 | $TSvars.Add("IsOnBattery", ((![bool]$AcConnected)).ToString()) 179 | } 180 | 181 | function Get-Architecture { 182 | 183 | $arch = "X86" 184 | 185 | if($env:PROCESSOR_ARCHITECTURE.Equals("AMD64")) { 186 | $arch = "X64" 187 | } 188 | 189 | $TSvars.Add("Architecture", $arch) 190 | } 191 | 192 | function Get-Processor { 193 | 194 | $proc = gwmi -Class 'Win32_Processor' | Select-Object -First '1' 195 | $TSvars.Add("ProcessorSpeed", $proc.MaxClockSpeed.ToString()) 196 | } 197 | 198 | function Get-Bitlocker { 199 | 200 | $IsBDE = $false 201 | $BitlockerEncryptionType = "N/A" 202 | $BitlockerEncryptionMethod = "N/A" 203 | 204 | $EncVols = Get-WmiObject -Namespace 'ROOT\cimv2\Security\MicrosoftVolumeEncryption' -Query "Select * from Win32_EncryptableVolume" -EA SilentlyContinue 205 | 206 | if ($EncVols) { 207 | 208 | foreach ($EncVol in $EncVols) { 209 | 210 | if($EncVol.ProtectionStatus -ne 0) { 211 | 212 | $EncMethod = [int]$EncVol.GetEncryptionMethod().EncryptionMethod 213 | 214 | if ($EncryptionMethods.ContainsKey($EncMethod)) { 215 | $BitlockerEncryptionMethod = $EncryptionMethods[$EncMethod] 216 | } 217 | 218 | $Status = $EncVol.GetConversionStatus(0) 219 | 220 | if ($Status.ReturnValue -eq 0) { 221 | if ($Status.EncryptionFlags -eq 0x00000001) { 222 | $BitlockerEncryptionType = "Used Space Only Encrypted" 223 | } 224 | else { 225 | $BitlockerEncryptionType = "Full Disk Encryption" 226 | } 227 | } 228 | else { 229 | $BitlockerEncryptionType = "Unknown" 230 | } 231 | 232 | $IsBDE = $true 233 | } 234 | } 235 | } 236 | 237 | $TSvars.Add("IsBDE", $IsBDE.ToString()) 238 | $TSvars.Add("BitlockerEncryptionMethod", $BitlockerEncryptionMethod) 239 | $TSvars.Add("BitlockerEncryptionType", $BitlockerEncryptionType) 240 | } 241 | 242 | function Get-UBR { 243 | if ($env:SystemDrive -eq "X:"){ 244 | $Info = DISM.exe /image:c:\ /Get-CurrentEdition 245 | $UBR = ($Info | Where-Object {$_ -match "Image Version"}) -replace "Image Version: " 246 | } 247 | else { 248 | $Info = DISM.exe /online /Get-CurrentEdition 249 | $UBR = ($Info | Where-Object {$_ -match "Image Version"}) -replace "Image Version: " 250 | } 251 | # Reset $LastExitCode to 0 if DISM errors 252 | $global:LastExitCode = 0 253 | if ($UBR) { 254 | #return $UBR 255 | $TSvars.Add("CDriveUBR", $UBR) 256 | } 257 | } 258 | 259 | function Get-MachineMatchID { 260 | $Manufacturer = (Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer 261 | $MachineMatchID = "Unknown" #HP, Intel, others 262 | 263 | if ($Manufacturer -match "Dell" -or $Manufacturer -match "Microsoft"){ 264 | $MachineMatchID = (Get-CimInstance -ClassName Win32_ComputerSystem).SystemSKUNumber 265 | } 266 | elseif ($Manufacturer -match "Lenovo"){ 267 | $MachineMatchID = ((Get-CimInstance -Class "Win32_Bios" -Namespace "root/cimv2").SMBIOSBIOSVersion).SubString(0, 4) 268 | } 269 | 270 | if ($MachineMatchID -eq "Unknown"){ 271 | $MachineMatchID = (Get-CimInstance -ClassName Win32_BaseBoard).Product 272 | } 273 | 274 | $TSvars.Add("MachineMatchID", $MachineMatchID) 275 | } 276 | 277 | Get-ComputerSystemProductInfo 278 | Get-ComputerSystemInfo 279 | Get-Product 280 | Get-BiosInfo 281 | Get-OsInfo 282 | Get-SystemEnclosureInfo 283 | Get-NicConfigurationInfo 284 | Get-MacInfo 285 | Get-BatteryStatus 286 | Get-Architecture 287 | Get-Processor 288 | Get-Bitlocker 289 | Get-UBR 290 | Get-MachineMatchID 291 | 292 | if($Debug) { 293 | $TSvars.Keys | Sort-Object |% { 294 | Write-Host "$($_) = $($TSvars[$_])" 295 | } 296 | } 297 | else { 298 | $tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment 299 | $temp = $tsenv.Value("OSDComputerName") 300 | $IsNotInPe = $tsenv.Value("_SMSTSInWinPE").ToLower().Equals("false") 301 | 302 | if ($IsNotInPe) { 303 | 304 | try { 305 | $CompInfoInFullOs = Get-ComputerInfo | Select OsLocale, WindowsInstallationType, WindowsProductName, TimeZone 306 | $TSvars.Add("OsLocale", $CompInfoInFullOs.OsLocale) 307 | $TSvars.Add("WindowsInstallationType", $CompInfoInFullOs.WindowsInstallationType) 308 | $TSvars.Add("WindowsProductName", $CompInfoInFullOs.WindowsProductName) 309 | $TSvars.Add("TimeZone", $CompInfoInFullOs.TimeZone) 310 | } 311 | catch { } 312 | } 313 | 314 | if(!$temp) { 315 | $TSvars.Add("OSDComputerName", $tsenv.Value("_SMSTSMachineName")) 316 | } 317 | 318 | $TSvars.Keys |% { 319 | $tsenv.Value($_) = $TSvars[$_].tostring() 320 | } 321 | } 322 | --------------------------------------------------------------------------------