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 {
param (
[string]$comp
[string]$comp,
[Parameter(Mandatory=$false)][string]$status
)
try {
$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}}
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}}
} 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 AttachedComputer -NotePropertyValue $comp
foreach($item in $usb){
@ -39,34 +44,35 @@ function Get-Devices {
$usb = $null
}
$monitors = @()
$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
if ($status -eq 'Online') {
$monitors = @()
$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
$PortsHash = @{
'DELL P170S'= @('DVI','VGA');
'DELL P2317H'= @('DP','HDMI','VGA');
'DELL P2314H'= @('DP','DVI','VGA');
'DELL P2312H'= @('DVI','VGA');
'DELL P2319H'= @('DP','HDMI','VGA');
'DELL P2422H'= @('DP','VGA');
'DELL P2412H'= @('DP','VGA','HDMI');
}
foreach($item in $monitors){
$portList = ''
$found = $false
foreach ($port in $PortsHash.($item.Description)) {
if ($port -eq $item.ActivePort) { $portList += '*'; $found = $true }
$portList += $port + ','
$PortsHash = @{
'DELL P170S'= @('DVI','VGA');
'DELL P2317H'= @('DP','HDMI','VGA');
'DELL P2314H'= @('DP','DVI','VGA');
'DELL P2312H'= @('DVI','VGA');
'DELL P2319H'= @('DP','HDMI','VGA');
'DELL P2422H'= @('DP','VGA');
'DELL P2412H'= @('DP','VGA','HDMI');
}
foreach($item in $monitors){
$portList = ''
$found = $false
foreach ($port in $PortsHash.($item.Description)) {
if ($port -eq $item.ActivePort) { $portList += '*'; $found = $true }
$portList += $port + ','
}
$portList = $portList -replace "\,$"
$item.Description = $item.Description + ' (' + $portList + ')'
if ($found -ne $true) { $item.Description += " *" + $item.ActivePort }
}
$portList = $portList -replace "\,$"
$item.Description = $item.Description + ' (' + $portList + ')'
if ($found -ne $true) { $item.Description += " *" + $item.ActivePort }
}
$out = @()
$out = @()
foreach($item in ($monitors + $usb)){
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
@ -217,7 +223,7 @@ Function Get-Monitor {
#Translates port numeric code to a readable port identifier
$activePorts[ $data.InstanceName ] = $ActivePortHash["$($data.VideoOutputTechnology)"]
#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
}
}
@ -231,7 +237,7 @@ Function Get-Monitor {
ForEach ($Monitor in $Monitors) {
#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)","")
} else {
$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
$Mon_Manufacturer_Friendly = $ManufacturerHash.$Mon_Manufacturer
If ($Mon_Manufacturer_Friendly -eq $null) {
If ($null -eq $Mon_Manufacturer_Friendly) {
$Mon_Manufacturer_Friendly = $Mon_Manufacturer
}

View file

@ -413,4 +413,11 @@ 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++
if ($compStatus -ne 'Online') {
Write-Warning "$comp is $compStatus unable to proccess command"
continue
Write-Warning "$comp is $compStatus skipping monitor query"
}
$out = Get-Devices $comp
$out = Get-Devices $comp $compStatus
if ($null -eq $out) {
Write-Warning "Unable to get device info for $comp"
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
-Added Wake flag to attempt to wake pc over LAN
-Added LastLogon field to SHSUser