PowerShell2.0之Windows排錯(五)查看硬件問題數組
硬件問題並不必定都和硬件有關,只要工做負荷在設計的範圍內,大部分電子設備均可以使用至關長的一段時間。爲了硬件正常工做,須要安裝相應的驅動程序。硬件廠商會爲其驅動程序添加數字簽名,添加數字簽名的驅動都是廠商通過大量測試後經過的,可以使設備高效運轉的驅動;未經簽名的驅動程序多是致使硬件問題的主要緣由。ide
爲了檢查硬件是否運行廠商認證的驅動程序,建立名爲「CheckSignedDeviceDrivers.ps1」的腳本,其代碼以下:測試
param(網站
$computer="localhost",設計
[switch]$unsigned,orm
[switch]$full,blog
[switch]$helpip
)字符串
function funline ($strIN)get
{
$num = $strIN.length
for($i=1 ; $i -le $num ; $i++)
{ $funline += "=" }
Write-Host -ForegroundColor green $strIN
Write-Host -ForegroundColor darkgreen $funline
}
function funHelp()
{
$helpText=@"
DESCRIPTION:
NAME: CheckSignedDeviceDrivers.ps1
Displays a listing of device drivers that are
and whether they are signed or not
PARAMETERS:
-computer the name of the computer
-unsigned lists unsigned drivers
-full lists Description, driverProviderName,
Driverversion,DriverDate, and infName
-help prints help file
SYNTAX:
CheckSignedDeviceDrivers.ps1 -computer munich -unsigned
Displays a listing of all unsigned drivers
on a computer named munich
CheckSignedDeviceDrivers.ps1 -unsigned -full
Displays a listing of all unsigned drivers on local
computer. Lists Description, driverProviderName,
Driverversion,DriverDate, and infName of the driver
CheckSignedDeviceDrivers.ps1 -computer munich -full
Displays a listing of all signed drivers
a computer named munich. Lists Description, driverProviderName,
Driverversion,DriverDate, and infName of the driver
CheckSignedDeviceDrivers.ps1 -help ?
Displays the help topic for the script
"@
$helpText
exit
}
if($help){ "Obtaining help ..." ; funhelp }
if($unsigned)
{ $filter = "isSigned = 'false'" ; $mode = "unsigned" }
ELSE
{ $filter = "isSigned = 'true'" ; $mode = "signed" }
$property = "Description", "driverProviderName", `
"Driverversion","DriverDate","infName"
$wmi = Get-WmiObject -Class Win32_PnPSignedDriver `
-computername $computer -property $property -filter $filter
funline("There are $($wmi.count) $mode drivers isted below:")
if($full)
{
format-list -InputObject $wmi -property `
$property
}
ELSE
{
format-table -inputobject $wmi -Property description
}
其中經過param語句聲明瞭4個參數,-computer用於指定操做的目標計算機;-unsigned是個switch參數,用於返回不曾簽名的驅動的查詢結果;-full參數列出有問題的驅動程序的詳細信息;-help參數用於顯示幫助文件。若是存在$unsigned變量,則將字符串「isSigned='false'」指定給$filter變量,該變量用於爲Get-WmiObject cmdlet提供-filter參數。隨後在$mode變量中保存狀態信息,用於指定WMI查詢的類型;若是不存在$unsigned變量,則檢查帶簽名的驅動程序。
經過數組方式指定相應的屬性名,建立變量$property並傳遞給Get-WmiObject cmdlet查詢Win32_PnPSignedDriver WMI類;另外還使用Count屬性統計符合條件的驅動程序數量。若是沒有簽名的驅動程序,則輸出以前計數器的值爲空,而不是0。該腳本的執行結果如圖8所示。
圖8 執行結果
須要強調的是因爲Windows Vista和Windows Server 2008與Windows XP硬件驅動的WMI管理類存在差異,因此該腳本僅顯示在Windows Vista和Windows Server 2008系統。
做者: 付海軍
出處:http://fuhj02.blog.51cto.com
版權:本文版權歸做者和51cto共有
轉載:歡迎轉載,爲了保存做者的創做熱情,請按要求【轉載】,謝謝
要求:未經做者贊成,必須保留此段聲明;必須在文章中給出原文鏈接;不然必究法律責任
我的網站: http://txj.lzuer.com/