Added DevicesUnplugged flag
This commit is contained in:
parent
ee682348fe
commit
2ec04bc03b
|
|
@ -12,7 +12,7 @@
|
|||
RootModule = 'Get-PC.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.4.6'
|
||||
ModuleVersion = '0.4.7'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ function Get-Devices {
|
|||
)
|
||||
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)} | 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 = Get-SCCM_USB $comp | Select-Object Manufacturer,Description,@{N="DeviceID\SerialNumber";E={$_.DeviceID}}
|
||||
}
|
||||
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
|
||||
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
|
||||
|
|
@ -55,8 +55,8 @@ function Get-Devices {
|
|||
'DELL P2314H'= @('DP','DVI','VGA');
|
||||
'DELL P2312H'= @('DVI','VGA');
|
||||
'DELL P2319H'= @('DP','HDMI','VGA');
|
||||
'DELL P2422H'= @('DP','VGA');
|
||||
'DELL P2412H'= @('DP','VGA','HDMI');
|
||||
'DELL P2422H'= @('DP','HDMI','VGA');
|
||||
'DELL P2412H'= @('DP','HDMI','VGA');
|
||||
}
|
||||
|
||||
foreach($item in $monitors){
|
||||
|
|
|
|||
142
Private/Get-DevicesUnplugged.ps1
Normal file
142
Private/Get-DevicesUnplugged.ps1
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
function Get-DevicesUnplugged {
|
||||
param (
|
||||
[string]$comp
|
||||
)
|
||||
if ($comp -eq $env:COMPUTERNAME) {
|
||||
$usb += Get-PnpDevice -Status UNKNOWN | Select-Object @{N="Description";E={$_.FriendlyName}},@{N="DeviceID\SerialNumber";E={$_.InstanceID}} | Add-Member -NotePropertyName Manufacturer -NotePropertyValue 'Unknown' -PassThru
|
||||
} else {
|
||||
$usb += Invoke-Command -ComputerName $comp -SessionOption $(New-PSSessionOption -NoMachineProfile) -ScriptBlock {
|
||||
Get-PnpDevice -Status UNKNOWN | Select-Object @{N="Description";E={$_.FriendlyName}},@{N="DeviceID\SerialNumber";E={$_.InstanceID}} | Add-Member -NotePropertyName Manufacturer -NotePropertyValue 'Unknown' -PassThru
|
||||
}
|
||||
}
|
||||
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
|
||||
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
|
||||
foreach($item in $usb){
|
||||
$friendlyNames = FindUSBDevice -deviceID $item.'DeviceID\SerialNumber'.ToString()
|
||||
|
||||
if($friendlyNames){
|
||||
$item.Manufacturer = $friendlyNames[0]
|
||||
if($item.Manufacturer.Length -le 5){
|
||||
continue
|
||||
}
|
||||
if($item.Manufacturer.Substring(0,5) -eq '[SHS]'){
|
||||
$item.Type = 'SHS Issued USB'
|
||||
$len = $item.Manufacturer.Length -1
|
||||
$item.Manufacturer = $item.Manufacturer[5..$len] -join ''
|
||||
}
|
||||
if($friendlyNames[1]){
|
||||
$item.Description = $friendlyNames[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
$usb = $usb | Sort-Object Manufacturer,Description
|
||||
for ($i = 0; $i -lt $usb.Count - 1; $i++) {
|
||||
if($usb[$i].Manufacturer -eq $usb[$i+1].Manufacturer -and $usb[$i].Description -eq $usb[$i+1].Description){
|
||||
$usb[$i].Manufacturer = '__DUPE__'
|
||||
}
|
||||
}
|
||||
$usb = $usb | Where-Object -Property Manufacturer -NE '__DUPE__'
|
||||
$usb = $usb | Sort-Object Type
|
||||
|
||||
$out = @()
|
||||
|
||||
foreach($item in ($monitors + $usb)){
|
||||
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
|
||||
$out += $item
|
||||
}
|
||||
$item = [PSCustomObject]@{ }
|
||||
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
|
||||
$out += $item
|
||||
|
||||
Write-Output $out
|
||||
}
|
||||
|
||||
|
||||
function FindUSBDevice {
|
||||
param (
|
||||
[string]$vid,
|
||||
[string]$p,
|
||||
[string]$deviceID
|
||||
)
|
||||
if($deviceID){
|
||||
$bool = $deviceID -match '(?<=VID_)(....)'
|
||||
if(!$bool){
|
||||
return $null
|
||||
}
|
||||
$vid = $Matches[0]
|
||||
$deviceID -match '(?<=PID_)(....)' | Out-Null
|
||||
$p = $Matches[0]
|
||||
}
|
||||
$SHSEquip = MatchSHSEquipment $vid $p
|
||||
if($SHSEquip){
|
||||
return ($SHSEquip[0],$SHSEquip[1])
|
||||
}
|
||||
$lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\USBIDs.txt'
|
||||
$usbIDs = Get-Content $lookupTablePath
|
||||
for ($i = 0; $i -lt $usbIDs.Count; $i++) {
|
||||
if ($usbIDs[$i] -match $vid){
|
||||
|
||||
if($usbIDs[$i][0] -eq "`t"){
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
$man = ($usbIDs[$i] -split ' ')
|
||||
$man = $man[2..$man.count] -join ' '
|
||||
|
||||
for ($y = $i+1; $y -lt $usbIDs.Count; $y++) {
|
||||
if($usbIDs[$y][0] -ne "`t"){
|
||||
return ($man,$null)
|
||||
}
|
||||
if($usbIDs[$y] -match $p){
|
||||
$dev = ($usbIDs[$y] -split ' ')
|
||||
$dev = $dev[2..$dev.count] -join ' '
|
||||
return ($man,$dev)
|
||||
}
|
||||
|
||||
}
|
||||
return ($man,$null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function MatchSHSEquipment {
|
||||
param (
|
||||
$vid,
|
||||
$p
|
||||
)
|
||||
$lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\SHSEquipmentLookup.txt'
|
||||
$usbIDs = Get-Content $lookupTablePath
|
||||
for ($i = 0; $i -lt $usbIDs.Count; $i++) {
|
||||
if ($usbIDs[$i] -match $vid){
|
||||
|
||||
if($usbIDs[$i][0] -eq "`t"){
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
$man = ($usbIDs[$i] -split ' ')
|
||||
$man = $man[2..$man.count] -join ' '
|
||||
|
||||
for ($y = $i; $y -lt $usbIDs.Count; $y++) {
|
||||
if($usbIDs[$y] -match $p){
|
||||
$dev = ($usbIDs[$y] -split ' ')
|
||||
$dev = $dev[2..$dev.count] -join ' '
|
||||
return ($man,$dev)
|
||||
}
|
||||
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ function Get-Hostname ([string]$name) {
|
|||
# Last resort checks
|
||||
$sccmMatches = Get-SCCM_HostnameMatch $name
|
||||
if ($SCCMMatches -and $SCCMMatches.Count -lt 2) {
|
||||
return $SCCMMatches.Name,''
|
||||
return $SCCMMatches,''
|
||||
} elseif (!$SCCMMatches) { $errMsg += "No SCCM match found`n" }
|
||||
elseif ($SCCMMatches.Count -ge 2) { $errMsg += "Many SCCM matches found`n" }
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ Function Get-PC {
|
|||
-ClearCCMCache | clears CCM cache, may fix software center
|
||||
-CMDB | only queries CMDB for info
|
||||
-Devices | shows connected monitors and usb devices
|
||||
-DevicesUnplugged | shows unplugged devices like scanners and printers
|
||||
-EventLog | pulls up errors in the event log for the last x days
|
||||
-Excel | exports collected data to csv and opens it with excel
|
||||
-Filesystem | access the file system
|
||||
|
|
@ -94,6 +95,7 @@ Function Get-PC {
|
|||
[Switch]$ClearCCMCache,
|
||||
[Switch]$CMDB,
|
||||
[switch]$Devices,
|
||||
[switch]$DevicesUnplugged,
|
||||
[Switch]$EventLog,
|
||||
[switch]$Excel,
|
||||
[Switch]$FileSystem,
|
||||
|
|
@ -373,6 +375,15 @@ Function Get-PC {
|
|||
continue
|
||||
}
|
||||
|
||||
if ($DevicesUnplugged) {
|
||||
if ($compStatus -ne 'Online') {
|
||||
Write-Warning "$comp is $compStatus unable to query unplugged devices"
|
||||
continue
|
||||
}
|
||||
$outPutArray += Get-DevicesUnplugged $comp
|
||||
continue
|
||||
}
|
||||
|
||||
#Pulls the event log for the past x days
|
||||
if ($EventLog) {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
Patch:
|
||||
-Fix Hostnames now check SCCM for a name match as a fallback
|
||||
-Fix Hostnames now check SCCM for a hostname match as a fallback
|
||||
-Fix Devices now reports correct ports on DELL P2422H monitor
|
||||
-Add DevicesUnplugged to report unplugged devices like scanners or printers
|
||||
|
||||
Patch: 2024-09-05
|
||||
-Fix Spark! hangs sometimes, added timeout in BatchInvokes
|
||||
|
|
|
|||
Loading…
Reference in a new issue