Advertisement
Guest User

Get-IntunePRInventory

a guest
Mar 26th, 2024
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $PRInvID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
  2.  
  3. $All = $null
  4.  
  5. Update-MSGraphEnvironment -SchemaVersion 'beta'
  6. Connect-MSGraph
  7.  
  8. $result = Invoke-MSGraphRequest -HttpMethod GET -Url "deviceManagement/deviceHealthScripts/$PRInvID/deviceRunStates?`$expand=managedDevice" | Get-MSGraphAllPages
  9. $success = $result | Where-Object -Property detectionState -EQ 'success'
  10. $DeviceNames = $success.managedDevice.deviceName | Get-Unique
  11.  
  12. $UniqueSuccess = $success | Sort-Object -Property lastSyncDateTime -Descending | Sort -Property ID -Unique
  13.  
  14. foreach ($record in $UniqueSuccess)
  15. {
  16.     $userPrincipalName = $null
  17.     if($record.preRemediationDetectionScriptOutput -like '`[*`]')
  18.     {
  19.         $userPrincipalName = ($success | where {($_.managedDevice.deviceName -eq $record.managedDevice.deviceName) -and -not ([string]::IsNullOrEmpty($_.managedDevice.userPrincipalName))}).managedDevice.userPrincipalName
  20.         $All += $(
  21.             if(($record.preRemediationDetectionScriptOutput -like '*"User":"DWM-*') -and ([string]::IsNullOrEmpty($record.managedDevice.userPrincipalName)) -and -not ([string]::IsNullOrEmpty($userPrincipalName)))
  22.             {
  23.                 write-host "$($record.managedDevice.deviceName) - Last logon user not present, but pulling from duplicate record"
  24.                 $record.preRemediationDetectionScriptOutput.replace('"SN":',"`"ComputerName`":`"$($record.managedDevice.deviceName)`",`"SerialNumber`":").replace('"User":"DWM-1"',"`"User`":`"$userPrincipalName`"") | ConvertFrom-Json
  25.             }
  26.             elseif(($record.preRemediationDetectionScriptOutput -like '*"User":"DWM-*') -and -not ([string]::IsNullOrEmpty($record.managedDevice.userPrincipalName)))
  27.             {
  28.                 write-host "$($record.managedDevice.deviceName) - Last logon user not present, but pulling from current record"
  29.                 $record.preRemediationDetectionScriptOutput.replace('"SN":',"`"ComputerName`":`"$($record.managedDevice.deviceName)`",`"SerialNumber`":").replace('"User":"DWM-1"',"`"User`":`"$($record.manageddevice.userPrincipalName)`"") | ConvertFrom-Json
  30.             }
  31.             else
  32.             {
  33.                 write-host "$($record.managedDevice.deviceName) - Last logon user already present or not present in any record"
  34.                 $record.preRemediationDetectionScriptOutput.replace('"SN":',"`"ComputerName`":`"$($record.managedDevice.deviceName)`",`"SerialNumber`":") | ConvertFrom-Json
  35.             }
  36.         )
  37.     }
  38. }
  39.  
  40. $Inventory = $true
  41.  
  42. while (-not([string]::IsNullOrEmpty($Inventory)))
  43. {
  44.     $Inventory = ($All | foreach {$_.psobject.properties.name} | select -Unique | foreach {[PSCustomObject]@{Inventory = $_}} | Out-GridView -Title 'Select Inventory' -OutputMode Multiple).Inventory
  45.     $Inventory | foreach {$All."$_" | Out-GridView -Title "$_"}
  46. }
  47.  
  48. <#
  49. $All.WMI_Win32_ComputerSystem | Out-GridView
  50. $All.WMI_Win32_ComputerSystemProduct | Out-GridView
  51. $All.WMI_Win32_SystemEnclosure | Out-GridView
  52. $All.WMI_Win32_OperatingSystem | Out-GridView
  53. $All.Reg_OSUpgradeCompat_Win11 | Out-GridView
  54. $All.Reg_Office_License | Out-GridView
  55. $All.WMI_Win32_LogicalDisk | Out-GridView
  56. $All.WMI_Win32_Processor | Out-GridView
  57. #$All.WMI_Win32_PhysicalMemory | Out-GridView
  58. $All.WMI_Win32_NetworkAdapter | Out-GridView
  59. $All.WMI_Win32_NetworkAdapterConfiguration | Out-GridView
  60. $All.WMI_Lenovo_WarrantyInformation | Out-GridView
  61. $All.WMI_Dell_WarrantyInformation | Out-GridView
  62. $All.WinEvent_Last_Login_User | Out-GridView
  63. #>
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement