Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $PRInvID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
- $All = $null
- Update-MSGraphEnvironment -SchemaVersion 'beta'
- Connect-MSGraph
- $result = Invoke-MSGraphRequest -HttpMethod GET -Url "deviceManagement/deviceHealthScripts/$PRInvID/deviceRunStates?`$expand=managedDevice" | Get-MSGraphAllPages
- $success = $result | Where-Object -Property detectionState -EQ 'success'
- $DeviceNames = $success.managedDevice.deviceName | Get-Unique
- $UniqueSuccess = $success | Sort-Object -Property lastSyncDateTime -Descending | Sort -Property ID -Unique
- foreach ($record in $UniqueSuccess)
- {
- $userPrincipalName = $null
- if($record.preRemediationDetectionScriptOutput -like '`[*`]')
- {
- $userPrincipalName = ($success | where {($_.managedDevice.deviceName -eq $record.managedDevice.deviceName) -and -not ([string]::IsNullOrEmpty($_.managedDevice.userPrincipalName))}).managedDevice.userPrincipalName
- $All += $(
- if(($record.preRemediationDetectionScriptOutput -like '*"User":"DWM-*') -and ([string]::IsNullOrEmpty($record.managedDevice.userPrincipalName)) -and -not ([string]::IsNullOrEmpty($userPrincipalName)))
- {
- write-host "$($record.managedDevice.deviceName) - Last logon user not present, but pulling from duplicate record"
- $record.preRemediationDetectionScriptOutput.replace('"SN":',"`"ComputerName`":`"$($record.managedDevice.deviceName)`",`"SerialNumber`":").replace('"User":"DWM-1"',"`"User`":`"$userPrincipalName`"") | ConvertFrom-Json
- }
- elseif(($record.preRemediationDetectionScriptOutput -like '*"User":"DWM-*') -and -not ([string]::IsNullOrEmpty($record.managedDevice.userPrincipalName)))
- {
- write-host "$($record.managedDevice.deviceName) - Last logon user not present, but pulling from current record"
- $record.preRemediationDetectionScriptOutput.replace('"SN":',"`"ComputerName`":`"$($record.managedDevice.deviceName)`",`"SerialNumber`":").replace('"User":"DWM-1"',"`"User`":`"$($record.manageddevice.userPrincipalName)`"") | ConvertFrom-Json
- }
- else
- {
- write-host "$($record.managedDevice.deviceName) - Last logon user already present or not present in any record"
- $record.preRemediationDetectionScriptOutput.replace('"SN":',"`"ComputerName`":`"$($record.managedDevice.deviceName)`",`"SerialNumber`":") | ConvertFrom-Json
- }
- )
- }
- }
- $Inventory = $true
- while (-not([string]::IsNullOrEmpty($Inventory)))
- {
- $Inventory = ($All | foreach {$_.psobject.properties.name} | select -Unique | foreach {[PSCustomObject]@{Inventory = $_}} | Out-GridView -Title 'Select Inventory' -OutputMode Multiple).Inventory
- $Inventory | foreach {$All."$_" | Out-GridView -Title "$_"}
- }
- <#
- $All.WMI_Win32_ComputerSystem | Out-GridView
- $All.WMI_Win32_ComputerSystemProduct | Out-GridView
- $All.WMI_Win32_SystemEnclosure | Out-GridView
- $All.WMI_Win32_OperatingSystem | Out-GridView
- $All.Reg_OSUpgradeCompat_Win11 | Out-GridView
- $All.Reg_Office_License | Out-GridView
- $All.WMI_Win32_LogicalDisk | Out-GridView
- $All.WMI_Win32_Processor | Out-GridView
- #$All.WMI_Win32_PhysicalMemory | Out-GridView
- $All.WMI_Win32_NetworkAdapter | Out-GridView
- $All.WMI_Win32_NetworkAdapterConfiguration | Out-GridView
- $All.WMI_Lenovo_WarrantyInformation | Out-GridView
- $All.WMI_Dell_WarrantyInformation | Out-GridView
- $All.WinEvent_Last_Login_User | Out-GridView
- #>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement