PowerShell2.0之Windows排错(一)启动故障排错
如果Windows Vista和Windows Server 2008無法正常啟動,則可以檢查引導配置文件是否出現錯誤;另外可以檢查啟動服務及其依存性。Windows中的一些服務依賴于其他服務、系統(tǒng)驅動程序和組件的加載順序。如果系統(tǒng)組件被停止或運行不正常,則依賴于它的服務會受到影響。
(1)檢查引導配置文件
檢查運行Windows Vista和Windows Server 2008的計算機引導配置文件通常可以為用戶解決引導有關的問題,提供很多有價值的信息。類似引導分區(qū)、引導目錄,以及Windows目錄等信息往往都對排除故障很有用,大多數情況下通過VBS腳本獲取這些信息需要花費很多時間。
創(chuàng)建名為“DisplayBootConfig.ps1”腳本讀取引導配置,其代碼如下:
param($computer="localhost", [switch]$help)
function funHelp()
{
$helpText=@"
DESCRIPTION:
NAME: DisplayBootConfig.ps1
Displays a boot up configuration of a Windows system
PARAMETERS:
-computer The name of the computer
-help prints help file
SYNTAX:
DisplayBootConfig.ps1 -computer WebServer
Displays boot up configuration of a computer named WebServer
DisplayBootConfig.ps1
Displays boot up configuration on local computer
DisplayBootConfig.ps1 -help
Displays the help topic for the script
"@
$helpText
exit
}
if($help){ "Obtaining help ..." ; funhelp }
$wmi = Get-WmiObject -Class win32_BootConfiguration `
-computername $computer
format-list -InputObject $wmi [a-z]*
該腳本使用param語句定義了$computer和$help變量,前者的默認值為localhost。設置-help參數為switch,即在使用該參數時不需要提供額外信息,并且使用Get-WmiObject cmdlet從Win32_BootConfiguration WMI類中獲取信息。如果需要,可以將$computer變量中的值提供給-computername參數。這樣可以通過Get-WmiObject cmdlet連接到遠程計算機,最終將返回的management對象傳遞給Format-List cmdlet。使用范圍運算符(range operator)[a-z]*選擇字符開頭的屬性,以過濾報告中的所有系統(tǒng)屬性(因為系統(tǒng)屬性均以下畫線開頭)。
該腳本的執(zhí)行結果如圖1所示。
圖1 獲取Windows引導配置信息
(2)檢查啟動進程
在Windows Vista和Windows Server 2008系統(tǒng)中有部分程序伴隨系統(tǒng)啟動,它們以不同啟動組的形式存在。很多惡意軟件和病毒以這種形式啟動,當操作系統(tǒng)啟動出現問題時需要檢查這些啟動組。
創(chuàng)建名為“DetectStartupPrograms.ps1”的腳本顯示本地或遠程計算機的自動運行程序的狀態(tài),并查看基本或完整的程序信息,其代碼如下:
param($computer="localhost", [switch]$full, [switch]$help)
function funHelp()
{
$helpText=@"
DESCRIPTION:
NAME: DetectStartUpPrograms.ps1
Displays a listing of programs that automatically start
PARAMETERS:
-computer the name of the computer
-full prints detailed information
-help prints help file
SYNTAX:
DetectStartUpPrograms.ps1 -computer WebServer -full
Displays name, command, location, and user information
about programs that automatically start on a computer named WebServer
DetectStartUpPrograms.ps1 -full
Displays name, command, location, and user information
about programs that automatically start on the local computer
DetectStartUpPrograms.ps1 -computer WebServer
Displays a listing of programs that automatically start on a computer named WebServer
DetectStartUpPrograms.ps1 -help ?
Displays the help topic for the script
"@
$helpText
exit
}
if($help){ "Obtaining help ..." ; funhelp }
if($full)
{ $property = "name", "command", "location", "user" }
else
{ $property = "name" }
Get-WmiObject -Class win32_startupcommand -computername $computer |
Sort-Object -property name |
format-list -property $property
該腳本中使用param語句定義了$computer、$full和$help變量,分別用于指定腳本作用的計算機及幫助信息。隨后定義了兩個switch參數,其中-full用于輸出完整的啟動程序信息;-help用于輸出幫助信息。
如果在腳本運行時提供了-full參數,則輸出程序的名稱、可執(zhí)行文件、路徑及用戶名等信息;否則僅顯示名稱。腳本中通過調用Get-WmiObject cmdlet獲得所有的自動運行程序,將結果對象用管道發(fā)送給Sort-Object cmdlet,同時分類屬性名稱。最后使用Format-List cmdlet選擇由$property變量指定的屬性輸出,該腳本的執(zhí)行結果如圖2所示。
圖2 執(zhí)行結果
?
作者: 付海軍
出處:http://fuhj02.cnblogs.com
版權:本文版權歸作者和博客園共有
轉載:歡迎轉載,為了保存作者的創(chuàng)作熱情,請按要求【轉載】,謝謝
要求:未經作者同意,必須保留此段聲明;必須在文章中給出原文連接;否則必究法律責任
個人網站: http://txj.lzuer.com/
轉載于:https://www.cnblogs.com/fuhj02/archive/2011/01/16/1937007.html
總結
以上是生活随笔為你收集整理的PowerShell2.0之Windows排错(一)启动故障排错的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言嵌入式系统编程修炼
- 下一篇: Open×××的新钩子设计