讀Getting Started With Windows PowerShell筆記

 
使用中Powershell的操作跟Linux中的終端操作很多地方是一致的,當然,還是有着Windows自己的特色,比如,不分大小寫。之前命令行中的命令大部分在這裏也可以用,而且用法一樣。
選中後點右鍵,即複製到剪切板。
不分大小寫,以下的幾個都是一樣的命令:
Get-Alias
get-alias
geT-ALIaS
輸命令時可以用Tab鍵補全。
可以加管道控制符,以及加more分屏輸出:
PS C:\Windows\system32> get-alias | more
CommandType Name ModuleName
----------- ---- ----------
Alias % -> ForEach-Object
Alias ? -> Where-Object
Alias ac -> Add-Content
Alias asnp -> Add-PSSnapin
Alias cat -> Get-Content
Alias cd -> Set-Location
Alias chdir -> Set-Location
Alias clc -> Clear-Content
Alias clear -> Clear-Host
Alias clhy -> Clear-History
Alias cli -> Clear-Item
Alias clp -> Clear-ItemProperty
Alias cls -> Clear-Host
Alias clv -> Clear-Variable
Alias cnsn -> Connect-PSSession
Alias compare -> Compare-Object
Alias copy -> Copy-Item
Alias cp -> Copy-Item
Alias cpi -> Copy-Item
Alias cpp -> Copy-ItemProperty
Alias cvpa -> Convert-Path
Alias dbp -> Disable-PSBreakpoint
Alias del -> Remove-Item
Alias diff -> Compare-Object
Alias dir -> Get-ChildItem
Alias dnsn -> Disconnect-PSSession
Alias ebp -> Enable-PSBreakpoint
Alias echo -> Write-Output
Alias epal -> Export-Alias
Alias epcsv -> Export-Csv
Alias epsn -> Export-PSSession
Alias erase -> Remove-Item
Alias etsn -> Enter-PSSession
Alias exsn -> Exit-PSSession
Alias fc -> Format-Custom
Alias fl -> Format-List
Alias foreach -> ForEach-Object
Alias ft -> Format-Table
Alias fw -> Format-Wide
Alias gal -> Get-Alias
Alias gbp -> Get-PSBreakpoint
Alias gc -> Get-Content
Alias gci -> Get-ChildItem
Alias gcm -> Get-Command
Alias gcs -> Get-PSCallStack
Alias gdr -> Get-PSDrive
-- More --
同樣的是回車往下一行,空格往下一屏。Ctrl+c,中止執行。
Alias也是給這些cmdlet起個別名,或者,叫暱稱?比如下面的三個,都是完全一樣的結果,倒是更方便了。
PS C:\Windows\system32> d:
PS D:\> dir
目錄: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
da--- 2007/4/17 10:43 Dynamips@EDURainbow
d---- 2012/12/1 10:22 My Documents
d---- 2012/11/7 10:38 NeoSpeech
d---- 2012/11/10 9:17 Program Files
d---- 2012/11/29 21:58 Program Files (x86)
PS D:\> ls
目錄: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
da--- 2007/4/17 10:43 Dynamips@EDURainbow
d---- 2012/12/1 10:22 My Documents
d---- 2012/11/7 10:38 NeoSpeech
d---- 2012/11/10 9:17 Program Files
d---- 2012/11/29 21:58 Program Files (x86)
PS D:\> get-childitem
目錄: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
da--- 2007/4/17 10:43 Dynamips@EDURainbow
d---- 2012/12/1 10:22 My Documents
d---- 2012/11/7 10:38 NeoSpeech
d---- 2012/11/10 9:17 Program Files
d---- 2012/11/29 21:58 Program Files (x86)
也可以加其他參數,參數可以只輸前幾個字母,只要沒有其他的參數的跟這些字母重複,造成不知道是哪個:
PS C:\Users\Denny> get-childitem -recurse | more
目錄: C:\Users\Denny
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2012/11/8 15:52 .sdtgui
d-r-- 2012/11/5 21:35 Contacts
d-r-- 2012/12/5 9:11 Desktop
d-r-- 2012/11/15 16:51 Documents
d-r-- 2012/12/4 21:30 Downloads
d-r-- 2012/11/5 21:35 Favorites
d-r-- 2012/11/5 21:35 Links
d-r-- 2012/11/5 21:35 Music
d-r-- 2012/11/14 8:52 Pictures
d-r-- 2012/11/5 21:35 Saved Games
d-r-- 2012/11/6 9:30 Searches
d-r-- 2012/11/5 21:35 Videos
-a--- 2012/11/23 9:16 11216 dlclient.history
-a--- 2012/11/23 9:16 167 dlclient.localstate
-a--- 2012/11/23 9:16 732 dlgmanager.config
-a--- 2012/11/8 15:52 100 sapinstAuth.txt
目錄: C:\Users\Denny\.sdtgui
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2012/11/8 15:52 download
d---- 2012/11/8 15:52 history
d---- 2012/11/8 15:52 htdoc
d---- 2012/11/8 15:52 log
-a--- 2012/11/8 15:52 1187 .sdt_keystore_nw2007
目錄: C:\Users\Denny\.sdtgui\log
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2012/11/8 15:52 480 FileService.log
-a--- 2012/11/8 15:52 42 frog.log
-a--- 2012/11/8 15:52 484 NotesService.log
-a--- 2012/11/8 15:52 836 SAPinstService.log
-a--- 2012/11/8 15:52 3829 sdtgui.log
-a--- 2012/11/8 15:52 0 sdtgui.out
-a--- 2012/11/8 15:52 0 sdtgui.trc
-- More --
列出下面所有子文件夾的文件。
輸出命令信息:
PS C:\Users\Denny> get-command | more
CommandType Name ModuleName
----------- ---- ----------
Alias Add-ProvisionedAppxPackage Dism
Alias Apply-WindowsUnattend Dism
Alias Get-ProvisionedAppxPackage Dism
Alias Initialize-Volume Storage
Alias Remove-ProvisionedAppxPackage Dism
Function A:
Function Add-BCDataCacheExtension BranchCache
Function Add-BitLockerKeyProtector BitLocker
Function Add-DnsClientNrptRule DnsClient
Function Add-DtcClusterTMMapping MsDtc
Function Add-InitiatorIdToMaskingSet Storage
Function Add-NetIPHttpsCertBinding NetworkTransition
Function Add-NetLbfoTeamMember NetLbfo
Function Add-NetLbfoTeamNic NetLbfo
Function Add-NetSwitchTeamMember NetSwitchTeam
Function Add-OdbcDsn Wdac
Function Add-PartitionAccessPath Storage
Function Add-PhysicalDisk Storage
Function Add-Printer PrintManagement
Function Add-PrinterDriver PrintManagement
Function Add-PrinterPort PrintManagement
以格式控制列出:
PS C:\Users\Denny> Get-Command | Format-List | more
DisplayName : Add-ProvisionedAppxPackage
CommandType : Alias
Definition :
ReferencedCommand :
ResolvedCommand :
DisplayName : Apply-WindowsUnattend
CommandType : Alias
Definition :
ReferencedCommand :
ResolvedCommand :
DisplayName : Get-ProvisionedAppxPackage
CommandType : Alias
Definition :
ReferencedCommand :
ResolvedCommand :
DisplayName : Initialize-Volume
CommandType : Alias
Definition :
ReferencedCommand :
ResolvedCommand :
DisplayName : Remove-ProvisionedAppxPackage
CommandType : Alias
Definition :
ReferencedCommand :
ResolvedCommand :
幫助信息:
PS C:\Users\Denny> get-help format-list
名稱
Format-List
語法
Format-List [[-Property] <Object[]>] [-GroupBy <Object>] [-View <string>] [-ShowError] [-DisplayError] [-Force] [-E
xpand <string> {CoreOnly | EnumOnly | Both}] [-InputObject <psobject>] [<CommonParameters>]
別名
fl
備註
Get-Help 在此計算機上找不到該 cmdlet 的幫助文件。它僅顯示部分幫助。
-- 若要下載並安裝包含此 cmdlet 的模塊的幫助文件,請使用 Update-Help。
-- 若要聯機查看此 cmdlet 的幫助主題,請鍵入: "Get-Help Format-List -Online" 或
轉到 http://go.microsoft.com/fwlink/?LinkID=113302。
其中下面的那個鏈接則是直接到format-list的幫助信息的。
安裝本地幫助:
PS C:\Users\Denny> update-help
提示需要以管理員身份運行才能更新這些幫助信息:
還有報錯,不過只是一小部分,暫時用不上:
終於出來了:
PS C:\Windows\system32> get-help format-list
名稱
Format-List
摘要
Formats the output as a list of properties in which each property appears on a new line.
語法
Format-List [[-Property] <Object[]>] [-DisplayError [<SwitchParameter>]] [-Expand <String>] [-Force [<SwitchParamet
er>]] [-GroupBy <Object>] [-InputObject <PSObject>] [-ShowError [<SwitchParameter>]] [-View <String>] [<CommonParam
eters>]
說明
The Format-List cmdlet formats the output of a command as a list of properties in which each property is displayed
on a separate line. You can use Format-List to format and display all or selected properties of an object as a list
(format-list *).
Because more space is available for each item in a list than in a table, Windows PowerShell displays more propertie
s of the object in the list, and the property values are less likely to be truncated.
相關鏈接
Online Version: http://go.microsoft.com/fwlink/?LinkID=113302
備註
若要查看示例,請鍵入: "get-help Format-List -examples".
有關詳細信息,請鍵入: "get-help Format-List -detailed".
若要獲取技術信息,請鍵入: "get-help Format-List -full".
有關在線幫助,請鍵入: "get-help Format-List -online"
加參數的命令,得到使用的例子:
PS C:\Users\Denny> Get-Help Format-List -Examples
名稱
Format-List
摘要
Formats the output as a list of properties in which each property appears on a new line.
-------------------------- EXAMPLE 1 --------------------------
PS C:\> get-service | format-list
This command formats information about services on the computer as a list. By default, the services are formatted a
s a table. The Get-Service cmdlet gets objects representing the services on the computer. The pipeline operator (|)
passes the results through the pipeline to Format-List. Then, the Format-List command formats the service informat
ion in a list and sends it to the default output cmdlet for display.
-------------------------- EXAMPLE 2 --------------------------
PS C:\> $a = get-childitem $pshome\*.ps1xml
PS C:\>format-list -InputObject $a
These commands display information about the PS1XML files in the Windows PowerShell directory as a list.
The first command gets the objects representing the files and stores them in the $a variable.
The second command uses Format-List to format information about objects stored in $a. This command uses the InputOb
ject parameter to pass the variable to Format-List, which then sends the formatted output to the default output cmd
let for display.
-------------------------- EXAMPLE 3 --------------------------
PS C:\> get-process | format-list -property name, basepriority, priorityclass
This command displays the name, base priority, and priority class of each process on the computer. It uses the Get-
Process cmdlet to get an object representing each process. The pipeline operator (|) passes the process objects thr
ough the pipeline to Format-List. Format-List formats the processes as a list of the specified properties. The "Pro
perty" parameter name is optional, so you can omit it.
-------------------------- EXAMPLE 4 --------------------------
PS C:\> get-process winlogon | format-list -property *
This command displays all of the properties of the Winlogon process. It uses the Get-Process cmdlet to get an objec
t representing the Winlogon process. The pipeline operator (|) passes the Winlogon process object through the pipel
ine to Format-List. The command uses the Property parameter to specify the properties and the * to indicate all pro
perties. Because the name of the Property parameter is optional, you can omit it and type the command as: "format-l
ist *". Format-List automatically sends the results to the default output cmdlet for display.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章