解答PowerShell:PowerShell原來的開發代號是Monad,原計劃是用以替代Windows中的命令列工具,但是後來微軟說它只是技術上的擴充。使用PowerShell,管理員可以做任何在圖形介面下所做的事情。Windows PowerShell 1.0可以運行在Windows XP SP2、Windows Server 2003和Windows Vista上。
1. 內建Cmdlets (即"commandlets")
Windows PowerShell中的所有Cmdlets都允許這樣的動名詞:get-service, get-process, stop-service, get-wmiobject.
2. 強大的萬用字元和操作對象
要得到以w開頭的服務及其依賴服務只要輸入:
PS> get-service w* format-list DisplayName, DependentServices
3. 在犯錯誤前測試命令
Windows PowerShell 有意向獨特的功能:Whatif ,可以不執行命令就告訴你命令執行結果.如:
PS> stop-service w3* -whatif
4. 擷取副本
PowerShell 可以開始和結束所有命令的副本,可以在指令碼中輕易測試命令並同時儲存.
PS> Start-Transcript -Path c:demodfoshow.txt
PS> Stop-Transcript
5. 從命令列發布Windows對話
因為Windows PowerShell位對象而最佳化,可以向.NET Framework一樣從命令列訪問COM對象,下列命令告訴你的Vista機器發表"Windows Vista and PowerShell"字串.
PS> $spVoice = new-object -com "SAPI.spvoice"
PS> $spVoice.Speak("Windows Vista and PowerShell")
6. 使用Windows PowerShell訪問諸如Windows Media Player 11等的應用程式
PS> $band = "The Posies"
PS> $player = New-object -com wmplayer.ocx
PS> $playlist = $player.mediacollection.getbyauthor($band)
PS> $player.openPlayer($playlist.item(0).sourceurl)
7. Windows PowerShell作為命令列儲存計算機
PowerShell可以完成基本的計算工作
PS> 2*2
不過,Windows PowerShell也可以快速解決儲存問題,例如,備份11GB的資料需要多少個700MB的CD.
PS> 11gb/700mb
那麼,需要多少個1000GB的儲存來備份每個320GB,共425個的Vista案頭呢?
PS > (320gb*425)/1000GB