Get-MMDRegistrationInfo.ps1
<#PSScriptInfo
.VERSION 1.1 .GUID feee5016-0fa7-479d-a48d-3ff3e824f7f5 .AUTHOR James Murray .COMPANYNAME Microsoft .COPYRIGHT .TAGS Microsoft Managed Desktop .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES Version 1.0: Original published version. Version 1.1: Updated Synopsis #> <# .SYNOPSIS Retrieves the Device Registration details from the current computers in the format supported by Microsoft Managed Desktop .DESCRIPTION This script uses WMI to retrieve properties needed by Microsoft Managed Desktop for the purposes of Device Registration .PARAMETER OutputFile The name of the CSV file to be created with the details for the computers. If not specified, the details will be returned to the PowerShell pipeline. #> [CmdletBinding()] param( [Parameter(Mandatory=$False)] [String] $OutputFile = "" ) Begin { # Initialize empty list $computers = @() $Name = @('localhost') } Process { foreach ($comp in $Name) { $session = New-CimSession $bad = $false # Get the common properties. Write-Verbose "Checking $comp" $serial = (Get-CimInstance -CimSession $session -Class Win32_BIOS).SerialNumber # Get the hash (if available) $devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap -Class MDM_DevDetail_Ext01 -Filter "InstanceID='Ext' AND ParentID='./DevDetail'") if ($devDetail -and (-not $Force)) { $hash = $devDetail.DeviceHardwareData } else { $hash = "" $bad = $true } $cs = Get-CimInstance -CimSession $session -Class Win32_ComputerSystem $make = $cs.Manufacturer.Trim() $model = $cs.Model.Trim() # Create a pipeline object $c = New-Object psobject -Property @{ "Serial Number" = $serial "Hardware Hash" = $hash "Manufacturer" = $make "Model" = $model } # Write the object to the pipeline or array if ($bad) { # Report an error when the hash isn't available Write-Error -Message "Unable to retrieve device hardware hash from computer $comp" -Category DeviceError } elseif ($OutputFile -eq "") { $c } else { $computers += $c } Remove-CimSession $session } } End { if ($OutputFile -ne "") { $computers | Select "Manufacturer","Model","Serial Number","Hardware Hash" | ConvertTo-CSV -NoTypeInformation | % {$_ -replace '"',''} | Out-File $OutputFile } } |