咱們能夠把powershell當成一個計算器。如鍵入命令行那樣輸入數學表達式,回車,powershell會自動計算並把結果輸出。經常使用的加減乘除模(+,-,*,/,%)運算和小括號表達式都支持。 shell
powershell也能自動識別計算機容量單位,包括KB,MB,GB,TB,PB windows
Powershell能像cmd同樣執行外部命令, api
如使用netstat –an 查看網絡端口鏈接 數組
使用ipconfig 查看本機ip地址 網絡
使用route print查看路由信息 dom
啓動控制檯CMD,使用exit退出CMD ide
查看CMD的幫助命令,能夠經過/c來接收命令參數(help) ui
Cmd /c help this
啓動外部程序,如notepad,但爲何不能啓動winword呢,由於winword的路勁未包含在powershell的環境變量裏 spa
咱們還可使用&來執行文本命令,如cmd == &"cmd.exe"
cmdlets是Powershell的內部命令,cmdlet的類型名爲System.Management.Automation.CmdletInfo,包含下列屬性和方法:
Name |
MemberType |
Definition |
Equals |
Method |
bool Equals(System.Object obj) |
GetHashCode |
Method |
int GetHashCode() |
GetType |
Method |
type GetType() |
ToString |
Method |
string ToString() |
CommandType |
Property |
System.Management.Automation.CommandTypes CommandType {get;} |
DefaultParameterSet |
Property |
System.String DefaultParameterSet {get;} |
Definition |
Property |
System.String Definition {get;} |
HelpFile |
Property |
System.String HelpFile {get;} |
ImplementingType |
Property |
System.Type ImplementingType {get;} |
Module |
Property |
System.Management.Automation.PSModuleInfo Module {get;} |
ModuleName |
Property |
System.String ModuleName {get;} |
Name |
Property |
System.String Name {get;} |
Noun |
Property |
System.String Noun {get;} |
OutputType |
Property |
System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.PSTypeName, System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] OutputType {get;} |
Parameters |
Property |
System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Management.Automation.ParameterMetadata, System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] Parameters {get;} |
ParameterSets |
Property |
System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.CommandParameterSetInfo, System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] ParameterSets {get;} |
PSSnapIn |
Property |
System.Management.Automation.PSSnapInInfo PSSnapIn {get;} |
Verb |
Property |
System.String Verb {get;} |
Visibility |
Property |
System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;} |
DLL |
ScriptProperty |
System.Object DLL {get=$this.ImplementingType.Assembly.Location;} |
HelpUri |
ScriptProperty |
System.Object HelpUri {get=try |
下面是所有的Cmdlets命令
每一個命令有一個動詞和名詞組成,命令的做用一目瞭然。
Name |
ModuleName |
Help |
Add-Computer |
Microsoft.PowerShell.Management |
|
Add-Content |
Microsoft.PowerShell.Management |
|
Add-History |
Microsoft.PowerShell.Core |
|
Add-Member |
Microsoft.PowerShell.Utility |
|
Add-PSSnapin |
Microsoft.PowerShell.Core |
|
Add-Type |
Microsoft.PowerShell.Utility |
|
Checkpoint-Computer |
Microsoft.PowerShell.Management |
|
Clear-Content |
Microsoft.PowerShell.Management |
|
Clear-EventLog |
Microsoft.PowerShell.Management |
|
Clear-History |
Microsoft.PowerShell.Core |
|
Clear-Item |
Microsoft.PowerShell.Management |
|
Clear-ItemProperty |
Microsoft.PowerShell.Management |
|
Clear-Variable |
Microsoft.PowerShell.Utility |
|
Compare-Object |
Microsoft.PowerShell.Utility |
|
Complete-Transaction |
Microsoft.PowerShell.Management |
|
Connect-WSMan |
Microsoft.WSMan.Management |
|
ConvertFrom-Csv |
Microsoft.PowerShell.Utility |
|
ConvertFrom-SecureString |
Microsoft.PowerShell.Security |
|
ConvertFrom-StringData |
Microsoft.PowerShell.Utility |
|
Convert-Path |
Microsoft.PowerShell.Management |
|
ConvertTo-Csv |
Microsoft.PowerShell.Utility |
|
ConvertTo-Html |
Microsoft.PowerShell.Utility |
|
ConvertTo-SecureString |
Microsoft.PowerShell.Security |
|
ConvertTo-Xml |
Microsoft.PowerShell.Utility |
|
Copy-Item |
Microsoft.PowerShell.Management |
|
Copy-ItemProperty |
Microsoft.PowerShell.Management |
|
Debug-Process |
Microsoft.PowerShell.Management |
|
Disable-ComputerRestore |
Microsoft.PowerShell.Management |
|
Disable-PSBreakpoint |
Microsoft.PowerShell.Utility |
|
Disable-PSSessionConfiguration |
Microsoft.PowerShell.Core |
|
Disable-WSManCredSSP |
Microsoft.WSMan.Management |
|
Disconnect-WSMan |
Microsoft.WSMan.Management |
|
Enable-ComputerRestore |
Microsoft.PowerShell.Management |
|
Enable-PSBreakpoint |
Microsoft.PowerShell.Utility |
|
Enable-PSRemoting |
Microsoft.PowerShell.Core |
|
Enable-PSSessionConfiguration |
Microsoft.PowerShell.Core |
|
Enable-WSManCredSSP |
Microsoft.WSMan.Management |
|
Enter-PSSession |
Microsoft.PowerShell.Core |
|
Exit-PSSession |
Microsoft.PowerShell.Core |
|
Export-Alias |
Microsoft.PowerShell.Utility |
|
Export-Clixml |
Microsoft.PowerShell.Utility |
|
Export-Console |
Microsoft.PowerShell.Core |
|
Export-Counter |
Microsoft.PowerShell.Diagnostics |
|
Export-Csv |
Microsoft.PowerShell.Utility |
|
Export-FormatData |
Microsoft.PowerShell.Utility |
|
Export-ModuleMember |
Microsoft.PowerShell.Core |
|
Export-PSSession |
Microsoft.PowerShell.Utility |
|
ForEach-Object |
Microsoft.PowerShell.Core |
|
Format-Custom |
Microsoft.PowerShell.Utility |
|
Format-List |
Microsoft.PowerShell.Utility |
|
Format-Table |
Microsoft.PowerShell.Utility |
|
Format-Wide |
Microsoft.PowerShell.Utility |
|
Get-Acl |
Microsoft.PowerShell.Security |
|
Get-Alias |
Microsoft.PowerShell.Utility |
|
Get-AuthenticodeSignature |
Microsoft.PowerShell.Security |
|
Get-ChildItem |
Microsoft.PowerShell.Management |
|
Get-Command |
Microsoft.PowerShell.Core |
|
Get-ComputerRestorePoint |
Microsoft.PowerShell.Management |
|
Get-Content |
Microsoft.PowerShell.Management |
|
Get-Counter |
Microsoft.PowerShell.Diagnostics |
|
Get-Credential |
Microsoft.PowerShell.Security |
|
Get-Culture |
Microsoft.PowerShell.Utility |
|
Get-Date |
Microsoft.PowerShell.Utility |
|
Get-Event |
Microsoft.PowerShell.Utility |
|
Get-EventLog |
Microsoft.PowerShell.Management |
|
Get-EventSubscriber |
Microsoft.PowerShell.Utility |
|
Get-ExecutionPolicy |
Microsoft.PowerShell.Security |
|
Get-FormatData |
Microsoft.PowerShell.Utility |
|
Get-Help |
Microsoft.PowerShell.Core |
|
Get-History |
Microsoft.PowerShell.Core |
|
Get-Host |
Microsoft.PowerShell.Utility |
|
Get-HotFix |
Microsoft.PowerShell.Management |
|
Get-Item |
Microsoft.PowerShell.Management |
|
Get-ItemProperty |
Microsoft.PowerShell.Management |
|
Get-Job |
Microsoft.PowerShell.Core |
|
Get-Location |
Microsoft.PowerShell.Management |
|
Get-Member |
Microsoft.PowerShell.Utility |
|
Get-Module |
Microsoft.PowerShell.Core |
|
Get-PfxCertificate |
Microsoft.PowerShell.Security |
|
Get-Process |
Microsoft.PowerShell.Management |
|
Get-PSBreakpoint |
Microsoft.PowerShell.Utility |
|
Get-PSCallStack |
Microsoft.PowerShell.Utility |
|
Get-PSDrive |
Microsoft.PowerShell.Management |
|
Get-PSProvider |
Microsoft.PowerShell.Management |
|
Get-PSSession |
Microsoft.PowerShell.Core |
|
Get-PSSessionConfiguration |
Microsoft.PowerShell.Core |
|
Get-PSSnapin |
Microsoft.PowerShell.Core |
|
Get-Random |
Microsoft.PowerShell.Utility |
|
Get-Service |
Microsoft.PowerShell.Management |
|
Get-TraceSource |
Microsoft.PowerShell.Utility |
|
Get-Transaction |
Microsoft.PowerShell.Management |
|
Get-UICulture |
Microsoft.PowerShell.Utility |
|
Get-Unique |
Microsoft.PowerShell.Utility |
|
Get-Variable |
Microsoft.PowerShell.Utility |
|
Get-WinEvent |
Microsoft.PowerShell.Diagnostics |
|
Get-WmiObject |
Microsoft.PowerShell.Management |
|
Get-WSManCredSSP |
Microsoft.WSMan.Management |
|
Get-WSManInstance |
Microsoft.WSMan.Management |
|
Group-Object |
Microsoft.PowerShell.Utility |
|
Import-Alias |
Microsoft.PowerShell.Utility |
|
Import-Clixml |
Microsoft.PowerShell.Utility |
|
Import-Counter |
Microsoft.PowerShell.Diagnostics |
|
Import-Csv |
Microsoft.PowerShell.Utility |
|
Import-LocalizedData |
Microsoft.PowerShell.Utility |
|
Import-Module |
Microsoft.PowerShell.Core |
|
Import-PSSession |
Microsoft.PowerShell.Utility |
|
Invoke-Command |
Microsoft.PowerShell.Core |
|
Invoke-Expression |
Microsoft.PowerShell.Utility |
|
Invoke-History |
Microsoft.PowerShell.Core |
|
Invoke-Item |
Microsoft.PowerShell.Management |
|
Invoke-WmiMethod |
Microsoft.PowerShell.Management |
|
Invoke-WSManAction |
Microsoft.WSMan.Management |
|
Join-Path |
Microsoft.PowerShell.Management |
|
Limit-EventLog |
Microsoft.PowerShell.Management |
|
Measure-Command |
Microsoft.PowerShell.Utility |
|
Measure-Object |
Microsoft.PowerShell.Utility |
|
Move-Item |
Microsoft.PowerShell.Management |
|
Move-ItemProperty |
Microsoft.PowerShell.Management |
|
New-Alias |
Microsoft.PowerShell.Utility |
|
New-Event |
Microsoft.PowerShell.Utility |
|
New-EventLog |
Microsoft.PowerShell.Management |
|
New-Item |
Microsoft.PowerShell.Management |
|
New-ItemProperty |
Microsoft.PowerShell.Management |
|
New-Module |
Microsoft.PowerShell.Core |
|
New-ModuleManifest |
Microsoft.PowerShell.Core |
|
New-Object |
Microsoft.PowerShell.Utility |
|
New-PSDrive |
Microsoft.PowerShell.Management |
|
New-PSSession |
Microsoft.PowerShell.Core |
|
New-PSSessionOption |
Microsoft.PowerShell.Core |
|
New-Service |
Microsoft.PowerShell.Management |
|
New-TimeSpan |
Microsoft.PowerShell.Utility |
|
New-Variable |
Microsoft.PowerShell.Utility |
|
New-WebServiceProxy |
Microsoft.PowerShell.Management |
|
New-WSManInstance |
Microsoft.WSMan.Management |
|
New-WSManSessionOption |
Microsoft.WSMan.Management |
|
Out-Default |
Microsoft.PowerShell.Utility |
|
Out-File |
Microsoft.PowerShell.Utility |
|
Out-GridView |
Microsoft.PowerShell.Utility |
|
Out-Host |
Microsoft.PowerShell.Utility |
|
Out-Null |
Microsoft.PowerShell.Utility |
|
Out-Printer |
Microsoft.PowerShell.Utility |
|
Out-String |
Microsoft.PowerShell.Utility |
|
Pop-Location |
Microsoft.PowerShell.Management |
|
Push-Location |
Microsoft.PowerShell.Management |
|
Read-Host |
Microsoft.PowerShell.Utility |
|
Receive-Job |
Microsoft.PowerShell.Core |
|
Register-EngineEvent |
Microsoft.PowerShell.Utility |
|
Register-ObjectEvent |
Microsoft.PowerShell.Utility |
|
Register-PSSessionConfiguration |
Microsoft.PowerShell.Core |
|
Register-WmiEvent |
Microsoft.PowerShell.Management |
|
Remove-Computer |
Microsoft.PowerShell.Management |
|
Remove-Event |
Microsoft.PowerShell.Utility |
|
Remove-EventLog |
Microsoft.PowerShell.Management |
|
Remove-Item |
Microsoft.PowerShell.Management |
|
Remove-ItemProperty |
Microsoft.PowerShell.Management |
|
Remove-Job |
Microsoft.PowerShell.Core |
|
Remove-Module |
Microsoft.PowerShell.Core |
|
Remove-PSBreakpoint |
Microsoft.PowerShell.Utility |
|
Remove-PSDrive |
Microsoft.PowerShell.Management |
|
Remove-PSSession |
Microsoft.PowerShell.Core |
|
Remove-PSSnapin |
Microsoft.PowerShell.Core |
|
Remove-Variable |
Microsoft.PowerShell.Utility |
|
Remove-WmiObject |
Microsoft.PowerShell.Management |
|
Remove-WSManInstance |
Microsoft.WSMan.Management |
|
Rename-Item |
Microsoft.PowerShell.Management |
|
Rename-ItemProperty |
Microsoft.PowerShell.Management |
|
Reset-ComputerMachinePassword |
Microsoft.PowerShell.Management |
|
Resolve-Path |
Microsoft.PowerShell.Management |
|
Restart-Computer |
Microsoft.PowerShell.Management |
|
Restart-Service |
Microsoft.PowerShell.Management |
|
Restore-Computer |
Microsoft.PowerShell.Management |
|
Resume-Service |
Microsoft.PowerShell.Management |
|
Select-Object |
Microsoft.PowerShell.Utility |
|
Select-String |
Microsoft.PowerShell.Utility |
|
Select-Xml |
Microsoft.PowerShell.Utility |
|
Send-MailMessage |
Microsoft.PowerShell.Utility |
|
Set-Acl |
Microsoft.PowerShell.Security |
|
Set-Alias |
Microsoft.PowerShell.Utility |
|
Set-AuthenticodeSignature |
Microsoft.PowerShell.Security |
|
Set-Content |
Microsoft.PowerShell.Management |
|
Set-Date |
Microsoft.PowerShell.Utility |
|
Set-ExecutionPolicy |
Microsoft.PowerShell.Security |
|
Set-Item |
Microsoft.PowerShell.Management |
|
Set-ItemProperty |
Microsoft.PowerShell.Management |
|
Set-Location |
Microsoft.PowerShell.Management |
|
Set-PSBreakpoint |
Microsoft.PowerShell.Utility |
|
Set-PSDebug |
Microsoft.PowerShell.Core |
|
Set-PSSessionConfiguration |
Microsoft.PowerShell.Core |
|
Set-Service |
Microsoft.PowerShell.Management |
|
Set-StrictMode |
Microsoft.PowerShell.Core |
|
Set-TraceSource |
Microsoft.PowerShell.Utility |
|
Set-Variable |
Microsoft.PowerShell.Utility |
|
Set-WmiInstance |
Microsoft.PowerShell.Management |
|
Set-WSManInstance |
Microsoft.WSMan.Management |
|
Set-WSManQuickConfig |
Microsoft.WSMan.Management |
|
Show-EventLog |
Microsoft.PowerShell.Management |
|
Sort-Object |
Microsoft.PowerShell.Utility |
|
Split-Path |
Microsoft.PowerShell.Management |
|
Start-Job |
Microsoft.PowerShell.Core |
|
Start-Process |
Microsoft.PowerShell.Management |
|
Start-Service |
Microsoft.PowerShell.Management |
|
Start-Sleep |
Microsoft.PowerShell.Utility |
|
Start-Transaction |
Microsoft.PowerShell.Management |
|
Start-Transcript |
Microsoft.PowerShell.Host |
|
Stop-Computer |
Microsoft.PowerShell.Management |
|
Stop-Job |
Microsoft.PowerShell.Core |
|
Stop-Process |
Microsoft.PowerShell.Management |
|
Stop-Service |
Microsoft.PowerShell.Management |
|
Stop-Transcript |
Microsoft.PowerShell.Host |
|
Suspend-Service |
Microsoft.PowerShell.Management |
|
Tee-Object |
Microsoft.PowerShell.Utility |
|
Test-ComputerSecureChannel |
Microsoft.PowerShell.Management |
|
Test-Connection |
Microsoft.PowerShell.Management |
|
Test-ModuleManifest |
Microsoft.PowerShell.Core |
|
Test-Path |
Microsoft.PowerShell.Management |
|
Test-WSMan |
Microsoft.WSMan.Management |
|
Trace-Command |
Microsoft.PowerShell.Utility |
|
Undo-Transaction |
Microsoft.PowerShell.Management |
|
Unregister-Event |
Microsoft.PowerShell.Utility |
|
Unregister-PSSessionConfiguration |
Microsoft.PowerShell.Core |
|
Update-FormatData |
Microsoft.PowerShell.Utility |
|
Update-List |
Microsoft.PowerShell.Utility |
|
Update-TypeData |
Microsoft.PowerShell.Utility |
|
Use-Transaction |
Microsoft.PowerShell.Management |
|
Wait-Event |
Microsoft.PowerShell.Utility |
|
Wait-Job |
Microsoft.PowerShell.Core |
|
Wait-Process |
Microsoft.PowerShell.Management |
|
Where-Object |
Microsoft.PowerShell.Core |
|
Write-Debug |
Microsoft.PowerShell.Utility |
|
Write-Error |
Microsoft.PowerShell.Utility |
|
Write-EventLog |
Microsoft.PowerShell.Management |
|
Write-Host |
Microsoft.PowerShell.Utility |
|
Write-Output |
Microsoft.PowerShell.Utility |
|
Write-Progress |
Microsoft.PowerShell.Utility |
|
Write-Verbose |
Microsoft.PowerShell.Utility |
|
Write-Warning |
Microsoft.PowerShell.Utility |
cmdlet 的名稱由一個動詞和一個名詞組成,其功能對用戶來說一目瞭然。可是對於一個常常使用powershell命令的人天天敲那麼多命令也很麻煩啊。能不能把命令縮短一點呢?因而"別名"就應運而生了。Powershell內部也實現了不少經常使用命令的別名。例如Get-ChildItem,列出當前的子文件或目錄。它有兩個別名:ls 和 dir,這兩個別名來源於unix 的shell和windows的cmd。
所以別名有兩個做用:
查詢別名所指的真實cmdlet命令。
查看可用別名
查看可用的別名,能夠經過" ls alias:" 或者 "Get-Alias"
如何查看全部以Remove打頭的cmdlet的命令的別名呢?
說明:dir alias:獲取的是別名的數組,經過where對數組元素進行遍歷,$_表明當前元素,alias的Definition爲String類型,由於powershell支持.net,.net中的string類有一個方法Startswith。經過where過濾集合在powershell中使用很是普遍。
有的cmdlet命令可能有2-3個別名,咱們能夠經過下面的命令查看全部別名和指向cmdlet的別名的個數。
建立本身的別名
給記事本建立一個別名,並查看別名
刪除別名 del alias:edit
Import-alias導入別名
Export-alias導出別名