PowerShell2.0之Windows排错(一)启动故障排错
如果Windows Vista和Windows Server 2008無(wú)法正常啟動(dòng),則可以檢查引導(dǎo)配置文件是否出現(xiàn)錯(cuò)誤;另外可以檢查啟動(dòng)服務(wù)及其依存性。Windows中的一些服務(wù)依賴(lài)于其他服務(wù)、系統(tǒng)驅(qū)動(dòng)程序和組件的加載順序。如果系統(tǒng)組件被停止或運(yùn)行不正常,則依賴(lài)于它的服務(wù)會(huì)受到影響。
(1)檢查引導(dǎo)配置文件
檢查運(yùn)行Windows Vista和Windows Server 2008的計(jì)算機(jī)引導(dǎo)配置文件通常可以為用戶(hù)解決引導(dǎo)有關(guān)的問(wèn)題,提供很多有價(jià)值的信息。類(lèi)似引導(dǎo)分區(qū)、引導(dǎo)目錄,以及Windows目錄等信息往往都對(duì)排除故障很有用,大多數(shù)情況下通過(guò)VBS腳本獲取這些信息需要花費(fèi)很多時(shí)間。
創(chuàng)建名為“DisplayBootConfig.ps1”腳本讀取引導(dǎo)配置,其代碼如下:
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語(yǔ)句定義了$computer和$help變量,前者的默認(rèn)值為localhost。設(shè)置-help參數(shù)為switch,即在使用該參數(shù)時(shí)不需要提供額外信息,并且使用Get-WmiObject cmdlet從Win32_BootConfiguration WMI類(lèi)中獲取信息。如果需要,可以將$computer變量中的值提供給-computername參數(shù)。這樣可以通過(guò)Get-WmiObject cmdlet連接到遠(yuǎn)程計(jì)算機(jī),最終將返回的management對(duì)象傳遞給Format-List cmdlet。使用范圍運(yùn)算符(range operator)[a-z]*選擇字符開(kāi)頭的屬性,以過(guò)濾報(bào)告中的所有系統(tǒng)屬性(因?yàn)橄到y(tǒng)屬性均以下畫(huà)線(xiàn)開(kāi)頭)。
該腳本的執(zhí)行結(jié)果如圖1所示。
圖1 獲取Windows引導(dǎo)配置信息
(2)檢查啟動(dòng)進(jìn)程
在Windows Vista和Windows Server 2008系統(tǒng)中有部分程序伴隨系統(tǒng)啟動(dòng),它們以不同啟動(dòng)組的形式存在。很多惡意軟件和病毒以這種形式啟動(dòng),當(dāng)操作系統(tǒng)啟動(dòng)出現(xiàn)問(wèn)題時(shí)需要檢查這些啟動(dòng)組。
創(chuàng)建名為“DetectStartupPrograms.ps1”的腳本顯示本地或遠(yuǎn)程計(jì)算機(jī)的自動(dòng)運(yùn)行程序的狀態(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語(yǔ)句定義了$computer、$full和$help變量,分別用于指定腳本作用的計(jì)算機(jī)及幫助信息。隨后定義了兩個(gè)switch參數(shù),其中-full用于輸出完整的啟動(dòng)程序信息;-help用于輸出幫助信息。
如果在腳本運(yùn)行時(shí)提供了-full參數(shù),則輸出程序的名稱(chēng)、可執(zhí)行文件、路徑及用戶(hù)名等信息;否則僅顯示名稱(chēng)。腳本中通過(guò)調(diào)用Get-WmiObject cmdlet獲得所有的自動(dòng)運(yùn)行程序,將結(jié)果對(duì)象用管道發(fā)送給Sort-Object cmdlet,同時(shí)分類(lèi)屬性名稱(chēng)。最后使用Format-List cmdlet選擇由$property變量指定的屬性輸出,該腳本的執(zhí)行結(jié)果如圖2所示。
圖2 執(zhí)行結(jié)果
?
作者: 付海軍
出處:http://fuhj02.cnblogs.com
版權(quán):本文版權(quán)歸作者和博客園共有
轉(zhuǎn)載:歡迎轉(zhuǎn)載,為了保存作者的創(chuàng)作熱情,請(qǐng)按要求【轉(zhuǎn)載】,謝謝
要求:未經(jīng)作者同意,必須保留此段聲明;必須在文章中給出原文連接;否則必究法律責(zé)任
個(gè)人網(wǎng)站: http://txj.lzuer.com/
轉(zhuǎn)載于:https://www.cnblogs.com/fuhj02/archive/2011/01/16/1937007.html
總結(jié)
以上是生活随笔為你收集整理的PowerShell2.0之Windows排错(一)启动故障排错的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C语言嵌入式系统编程修炼
- 下一篇: Open×××的新钩子设计