Updated Devices to query SCCM when offline

This commit is contained in:
Zachary Gorman 2024-06-24 14:11:07 -07:00
parent c6457d4684
commit 1646d2cdec
4 changed files with 49 additions and 33 deletions

View file

@ -1,9 +1,14 @@
function Get-Devices { function Get-Devices {
param ( param (
[string]$comp [string]$comp,
[Parameter(Mandatory=$false)][string]$status
) )
try { try {
if ($status -eq "Online") {
$usb = Get-WmiObject Win32_USBControllerDevice -ComputerName $comp | ForEach-Object {[wmi]($_.Dependent)} | Sort-Object Manufacturer,Description,DeviceID | Select-Object Manufacturer,Description,@{N="DeviceID\SerialNumber";E={$_.DeviceID}} $usb = Get-WmiObject Win32_USBControllerDevice -ComputerName $comp | ForEach-Object {[wmi]($_.Dependent)} | Sort-Object Manufacturer,Description,DeviceID | Select-Object Manufacturer,Description,@{N="DeviceID\SerialNumber";E={$_.DeviceID}}
} else {
$usb = Get-SCCM_USB $comp | Sort-Object Manufacturer,Description,DeviceID | Select-Object Manufacturer,Description,@{N="DeviceID\SerialNumber";E={$_.DeviceID}}
}
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB $usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp $usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
foreach($item in $usb){ foreach($item in $usb){
@ -39,6 +44,7 @@ function Get-Devices {
$usb = $null $usb = $null
} }
if ($status -eq 'Online') {
$monitors = @() $monitors = @()
$monitors += Get-Monitor $comp | Select-Object Manufacturer,@{N='Description';E={$_.Model}},@{N="DeviceID\SerialNumber";E={$_.SerialNumber}},AttachedComputer,ActivePort $monitors += Get-Monitor $comp | Select-Object Manufacturer,@{N='Description';E={$_.Model}},@{N="DeviceID\SerialNumber";E={$_.SerialNumber}},AttachedComputer,ActivePort
$monitors | Add-Member -NotePropertyName Type -NotePropertyValue Monitor $monitors | Add-Member -NotePropertyName Type -NotePropertyValue Monitor
@ -64,10 +70,10 @@ function Get-Devices {
$item.Description = $item.Description + ' (' + $portList + ')' $item.Description = $item.Description + ' (' + $portList + ')'
if ($found -ne $true) { $item.Description += " *" + $item.ActivePort } if ($found -ne $true) { $item.Description += " *" + $item.ActivePort }
} }
}
$out = @() $out = @()
foreach($item in ($monitors + $usb)){ foreach($item in ($monitors + $usb)){
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices') $item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
$out += $item $out += $item
@ -217,7 +223,7 @@ Function Get-Monitor {
#Translates port numeric code to a readable port identifier #Translates port numeric code to a readable port identifier
$activePorts[ $data.InstanceName ] = $ActivePortHash["$($data.VideoOutputTechnology)"] $activePorts[ $data.InstanceName ] = $ActivePortHash["$($data.VideoOutputTechnology)"]
#Uses the raw code if the code isn't recognized (it's a really weird one) #Uses the raw code if the code isn't recognized (it's a really weird one)
if ($activePorts[ $data.InstanceName ] -eq $null) { if ($null -eq $activePorts[ $data.InstanceName ]) {
$activePorts[ $data.InstanceName ] = $data.VideoOutputTechnology $activePorts[ $data.InstanceName ] = $data.VideoOutputTechnology
} }
} }
@ -231,7 +237,7 @@ Function Get-Monitor {
ForEach ($Monitor in $Monitors) { ForEach ($Monitor in $Monitors) {
#Grabs respective data and converts it from ASCII encoding and removes any trailing ASCII null values #Grabs respective data and converts it from ASCII encoding and removes any trailing ASCII null values
If ([System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName) -ne $null) { If ($null -ne [System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName)) {
$Mon_Model = ([System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName)).Replace("$([char]0x0000)","") $Mon_Model = ([System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName)).Replace("$([char]0x0000)","")
} else { } else {
$Mon_Model = $null $Mon_Model = $null
@ -245,7 +251,7 @@ Function Get-Monitor {
#Sets a friendly name based on the hash table above. If no entry found sets it to the original 3 character code #Sets a friendly name based on the hash table above. If no entry found sets it to the original 3 character code
$Mon_Manufacturer_Friendly = $ManufacturerHash.$Mon_Manufacturer $Mon_Manufacturer_Friendly = $ManufacturerHash.$Mon_Manufacturer
If ($Mon_Manufacturer_Friendly -eq $null) { If ($null -eq $Mon_Manufacturer_Friendly) {
$Mon_Manufacturer_Friendly = $Mon_Manufacturer $Mon_Manufacturer_Friendly = $Mon_Manufacturer
} }

View file

@ -414,3 +414,10 @@ Function Get-SCCMChassisType($ComputerName){
} }
Function Get-SCCM_USB($ComputerName) {
$usbDevicesQuery = "select SMS_G_System_USB_DEVICE.* from SMS_R_System inner join
SMS_G_System_USB_DEVICE on SMS_G_System_USB_DEVICE.ResourceID =
SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
return Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $usbDevicesQuery
}

View file

@ -337,11 +337,10 @@ Function Get-PC {
$PCID++ $PCID++
if ($compStatus -ne 'Online') { if ($compStatus -ne 'Online') {
Write-Warning "$comp is $compStatus unable to proccess command" Write-Warning "$comp is $compStatus skipping monitor query"
continue
} }
$out = Get-Devices $comp $out = Get-Devices $comp $compStatus
if ($null -eq $out) { if ($null -eq $out) {
Write-Warning "Unable to get device info for $comp" Write-Warning "Unable to get device info for $comp"
continue continue

View file

@ -1,3 +1,7 @@
Patch: 2024-06-24
-Add option in UserProfileBackup to specify custom path
-Fix Apps so no longer creates profile
-Update Devices to query SCCM when PC offline
Patch: 2024-06-12 Patch: 2024-06-12
-Added Wake flag to attempt to wake pc over LAN -Added Wake flag to attempt to wake pc over LAN
-Added LastLogon field to SHSUser -Added LastLogon field to SHSUser