使用中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.
转载于:https://blog.51cto.com/lightguide/1078859