- <#
- .SYNOPSIS
- Uses Win32_PNPEntity to return information about non-working devices.
- .DESCRIPTION
- This script calls Get-WmiObject to retrieve plug and play details,
- then formats and displays non-working devices. The script also has to
- work around how WMI returns 0 and 1 object (i.e. no $obj.count).
- This is also sample 6 on http://msdn.microsoft.com/en-us/library/aa394587(VS.85).aspx
- recoded with PowerShell.
- .NOTES
- File Name : Get-NonWorkingDevices.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Script posted to:
- http://www.pshscripts.blogspot.com
- Original MSDN Page
- http://msdn.microsoft.com/en-us/library/aa394587(VS.85).aspx
- .EXAMPLE
- PS C:\foo> Get-NonWorkingDevices.ps1
- No bad devices on Cookham8
- .EXAMPLE
- PS C:\foo> Get-NonWorkingDevices.ps1
- Total Bad devices on Cookham8: 1
- Name : NETGEAR FA311v2 PCI Adapter - Virtual Network
- Class Guid : {4d36e972-e325-11ce-bfc1-08002be10318}
- Description : Microsoft Virtual Network switch Adapter
- Device ID : ROOT\VMS_MP\0001
- Manufacturer :
- PNP Device Id : ROOT\VMS_MP\0001
- Service Name : VMSMP
- #>
- ###
- # Start of Script
- ###
- # Get non-working devices:
- $BadDevices = Get-WmiObject Win32_PNPEntity | Where {$_.ConfigManagerErrorcode -ne 0}
- # Display bad devices
- $Hostname = Hostname
- if (!$BadDevices) {
- "No bad devices on {0}" -f $Hostname
- } # end if
- else {
- if (!$BadDevices.Count) {$Count=1} else {$Count=$BadDevices.count}
- "Total Bad devices on {0}: {1}" -f $Hostname, $Count
- foreach ($Device in $BadDevices) {
- "Name : {0}" -f $Device.Name
- "Class Guid : {0}" -f $Device.Classguid
- "Description : {0}" -f $Device.Description
- "Device ID : {0}" -f $Device.Deviceid
- "Manufacturer : {0}" -f $Device.Manufactuer
- "PNP Device Id : {0}" -f $Device.PNPDeviceID
- "Service Name : {0}" -f $Device.Service
- ""
- } # End of ForEach
- } # End of Else
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Sunday 4 January 2009
Get-NonWorkingDevices.ps1
Labels:
powershell,
PowerShell scripts,
Win32_PointingDevice,
wmi
Subscribe to:
Post Comments (Atom)
2 comments:
Do you know how I would be able to have all the data for the bad devices sent out in an email? I know how to send an email with PowerShell, I just can't seem to get the information into the email.
Sure!
First, you'd need to adapt the script itself (to add or remove specific properties being displayed.
Next you would adapt the script for any networking - do you want to run the script centrally against remote systems, or do you want to remotely run teh script and have the invidual scripts run from one system and drag the data across the net. There are advantages and disavantages to both so you need to examine your options.
Finally, once you have the information, ou build an email message using the system.net.mail classes/methods. I have a couple on here - see http://pshscripts.blogspot.com/search/label/system.net.mail. I'm slowly getting around to writing a longer set of articles on mail, powerehell and the .NET related classes.
Post a Comment