Windows Powershell alias _powershell

Source: Internet
Author: User
Tags aliases

Brief description
In Windows PowerShell, aliases are alternative names for cmdlets or other commands.

Detailed description
Aliases are cmdlet or commands (for example: functions, scripts, files, executables.) Alternative name, or a nickname. You can use aliases where commands are used.

The name of the cmdlet is made up of a verb and a noun whose function is clear to the user. But it is also troublesome for a person who often uses the PowerShell command to knock so many orders every day. Can you shorten the order? So the "alias" was born. PowerShell also implements a number of aliases for commonly used commands. For example, Get-childitem lists the current child files or directories. It has two aliases: Ls and dir, both from the Unix shell and from Windows CMD.
Therefore the alias has two functions:

Inheritance: Inheriting Unix-shell and Windows-cmd.
Convenient: Convenient for users to use.
Processing aliases:
Queries the True cmdlet command that the alias refers to.

PS c:\ps> get-alias-name ls

commandtype   name                        Definition
-----------   ----                        ----------
Alias      ls                         get-childitem

PS c:\ps> get-alias-name dir

commandtype   name                        Definition
-----------   ----                        ----------
Alias      dir                         get-childitem

PS c:\ps> Get-alias-name FL

CommandType   name                        Definition
-----------   ----                        ----------
Alias      fl                         format-list

PS c:\ps> get-alias-name ft

CommandType   name                        Definition
-----------   ----                        ----------
Alias      ft                         format-table

To view available aliases
View available aliases, either through "LS alias:" or "Get-alias"
How do I see all the aliases for the commands of the cmdlet with the remove?

PS c:\ps> dir alias: | where {$_.                        Definition.startswith ("Remove")} CommandType Name Definition--------------- ----------alias del Remove-item alias Erase Remove-item A                          Lias RBP Remove-psbreakpoint Alias Rd Remove-item alias Rdr                         Remove-psdrive alias Ri Remove-item alias RJB Remove-job alias RM remove-item alias RmDir Remove-item Al IAS Rmo Remove-module alias Rp Remove-itemproperty alias RS                         N remove-pssession alias Rsnp remove-pssnapin alias RV
 Remove-variable Alias rwmi Remove-wmiobject

Description: Dir alias: Gets an array of aliases, which is traversed by the where array element, $_ represents the current element, and the definition of the alias is string type, Because the string class in PowerShell support. Net,.net has a method startswith. The where filter set is widely used in PowerShell.

Some cmdlet commands may have 2-3 individual names, and we can view all aliases and the number of aliases to the cmdlet by using the following command.

PS c:\ps> ls alias: | Group-object Definition | Sort-descending count Count Name Group--------------6 Remove-item {del, erase, RD, RI ...
  .} 3 set-location {CD, CHDIR, SL} 3 get-history {ghy, H, History} 3 Get-childitem {dir, GCI, ls} 3 G Et-content {cat, GC, type} 3 Move-item {mi, move, mv} 3 Copy-item {Copy, CP, CPI} 2 Start-pro Cess {saps, start} 2 set-variable {Set, SV} 2 Write-output {echo, Write} 2 get-process {GPS , PS} 2 invoke-history {ihy, R} 2 new-psdrive {mount, NDR} 2 stop-process {Kill, SPPs} 2 rename-  Item {ren, rni} 2 get-location {GL, pwd} 2 Compare-object {Compare, diff} 2 where-object {?, where} 2 foreach-object {%, ForEach} 2 clear-host {clear, CLS} 1 Out-host {oh} 1 New-pssessio  n {NSN} 1 new-variable {NV} 1 Out-gridview {OGV} 1 pop-location     {POPD} 1 tee-object {Tee} 1 remove-psbreakpoint {RBP} 1 receive-job {RCJB} 1 push-location      {pushd} 1 mkdir {MD} 1 Measure-object {Measure} 1 Help {mans} 1 Remove-pssnapin {RSNP} 1 out-printer {LP} 1 New-item {ni} 1 new-module {NMO} 1 New-alias {nal} 1 M Ove-itemproperty {MP} 1 wait-job {WJB} 1 remove-psdrive {RDR} 1 start-service {SASV} 1 set- Psbreakpoint {SBP} 1 set-itemproperty {SP} 1 start-job {SAJB} 1 Set-alias {sal} 1 START-SL        eep {sleep} 1 set-item {si} 1 select-object {Select} 1 set-content {SC} 1 Sort-object {sort} 1 Remove-wmiobject {RWMI} 1 remove-module {RMO} 1 rename-itemproperty {RNP} 1 Stop-serv Ice {SPSV} 1 set-wmiinstance {SWMI} 1 remove-job {RJB} 1 remove-variable {RV} 1 Resolve-pat h {RVPA} 1 stop-Job {SPJB} 1 Remove-itemproperty {rp} 1 remove-pssession {RSN} 1 exit-pssession {exsn} 1 forma T-custom {FC} 1 enter-pssession {ETSN} 1 export-csv {epcsv} 1 export-pssession {EPSN} 1 Form at-list {FL} 1 get-psbreakpoint {GBP} 1 Get-command {GCM} 1 Get-alias {gal} 1 Format-tab        Le {ft} 1 format-wide {FW} 1 Export-alias {Epal} 1 clear-history {clhy} 1 Clear-item    {CLI} 1 clear-content {CLC} 1 add-content {AC} 1 Add-pssnapin {ASNP} 1 Clear-itemproperty      {CLP} 1 disable-psbreakpoint {DBP} 1 enable-psbreakpoint {EBP} 1 Convert-path {CVPA} 1 clear-variable      {CLV} 1 copy-itemproperty {CPP} 1 invoke-expression {IEX} 1 Invoke-item {II} 1 Invoke-command     {ICM} 1 get-variable {GV} 1 get-wmiobject {GWMI} 1 Import-alias {Ipal} 1 Powershell_ise.exe {ise} 1 invoke-wmimethod {IWMI} 1 import-pssession {IPSN} 1 import-csv {ipcsv} 1 import-module {IPMO} 1 Get-uni que {gu} 1 get-job {GJB} 1 get-member {GM} 1 Get-item {GI} 1 Get-pscallstack {
  GCS} 1 get-psdrive {GDR} 1 get-module {GMO} 1 get-pssnapin {GSNP} 1 get-service {GSV}
 1 get-pssession {GSN} 1 get-itemproperty {GP} 1 group-object {Group}

Create your own alias
Create an alias for Notepad and view the alias;

PS c:\ps> set-alias-name edit-value notepad
ps c:\ps> edit
PS c:\ps> $alias: Edit
Notepad

Remove your own alias
Aliases are not deleted, and custom aliases are automatically cleared when PowerShell exits. However, be assured that PowerShell built-in aliases (such as LS,DIR,FL, etc.) will not be cleared. If you have to delete the alias manually. Please use

PS c:\ps> del Alias:edit Save your Alias
You can use Export-alias to export aliases to files, and then import them through Import-alias when needed. However, there may be an exception when importing, indicating that the alias already exists and cannot be imported:

PS c:\ps> Import-alias Alias.ps1 Import-alias:alias not allowed because a Alias with the
name ' AC ' already exist S.
At line:1 char:13
+ import-alias <<<< alias.ps1
  + categoryinfo     : resourceexists: (ac:string) [ Import-alias], sessionstateexception
  + fullyqualifiederrorid:aliasalreadyexists, Microsoft.PowerShell.Commands.ImportAliasCommand

You can then use force to force the import.

PS c:\ps> export-alias alias.ps1
PS c:\ps> import-alias-force alias.ps1


For example, if you set the alias "Gas" for get-authenticodesignature, you can enter it directly:

Gas C:\SCRIPTS\SQLSCRIPT.PS1


Without having to enter:

Get-authenticodesignature C:\SCRIPTS\SQLSCRIPT.PS1

If you have the alias "word" set for Microsoft Word, you can enter it directly:

Word

Without having to enter:

"C:\Program Files\Microsoft Office\Office11\Winword.exe"

Pre-defined aliases

Windows PowerShell has predefined parts of aliases, such as "CDs" and "CHDIR" are set-location aliases, and "Ls" and "dir" are get-childitem aliases.

To find all aliases in the system, including the intended alias, enter the following command:

Get-alias

Alias-related cmdlets

Windows PowerShell contains several cmdlets for manipulating aliases.

· Get-alias: Gets the alias in the current session.
· New-alias: Create a new alias.
· Set-alias: Create or modify an alias.
· Export-alias: Exports one or more aliases to a file.
· Import-alias: Import a single file to Windows PowerShell.

For more information on cmdlets, enter:

Get-help <cmdlet-name>-detailed

For example:

Get-help export-alias-detailed

Create Alias
Create a new alias, you can use the New-alias cmdlet. For example, to create a "GH" Alias for Get-help, enter,

New-alias-name Gh-value Get-help

You can use this alias in the command as if you were using the full cmdlet name and various parameters.

For example, to get the details of the Get-wmiobject cmdlet, you just type:

Get-help get-wmiobject-detailed

Or

GH get-wmiobject-detailed

Save Alias
The alias you create is valid only in the current session. To use aliases in different sessions, you must write the definition of the alias to your Windows PowerShell configuration file, or use Export-alias to store the alias in a file.

Find aliases
To display all aliases on the current console, including Windows PowerShell predefined aliases, aliases defined in your Windows PowerShell configuration file, aliases that you create in the current session, as long as you enter:

Get-alias

If you need a specific alias, specify the name parameter for Get-alias. For example, to get the alias that begins with "P", enter

Get-alias-name p*

To find all aliases for a particular cmdlet, you can enter:

Get-alias | Where-object {$_. Definition-eq "<cmdlet-name>"}

For example:

Get-alias | Where-object {$_. Definition-eq "Remove-item"}

Create an alias for a command with parameters

You can give aliases to cmdlet, scripts, functions, or executable files. But you cannot set an alias for a command with parameters. For example, you can set an alias for "Get-eventlog", but you cannot set an alias for "Get-eventlog-logname Security."

You can only solve this problem by creating a function that contains the command. For example, the following command creates a function called "Seclog", which can represent the "get-eventlog-logname Security" command.

function Seclog {get-eventlog-logname security}

Now you can type the name "Seclog" to simplify the previous command, and you can also create aliases for the function "Seclog".

For information about functions, enter:

Get-help about_function

Alias Object

The

Windows PowerShell alias is actually an instance object of Class System.Management.Automation.AliasInfo. For information about object types, see the topic "Aliasinfo Class" in MSDN.
 
To view the properties and methods on the alias object, first get the alias object and pass it to the Get-member cmdlet by pipeline. For example,
 
Get-alias | get-member
  ;
to view the property values for a particular alias, such as Alias "Dir", get the alias and pass it to the Format-list cmdlet through a pipe. For example, the following code takes the alias "dir" Object first, passing it to the Format-list cmdlet, All properties of the alias "dir" are displayed by assigning a value of Format-list's Parameter property to all (*).
 
Get-alias-name dir | format-list-property *
 
WINDOWS PowerShell alias provider

Windows PowerShell alias Provider (Translator Note: A provider is similar to the user's file system directory structure, Microsoft developers through MVC This design idea, the variable, registry, alias and other resources management, abstract as file system management. This allows users to access a variety of resources using a unified syntax. PowerShell developers can also extend other provider for PowerShell.) So that in Windows PowerShell, viewing aliases is like browsing the file system drive. The
 
alias provider provides an "Alias:" Drive (Translator: virtual drive, only valid in PowerShell). To enter the alias: drive, enter:
 
set-location alias:
 
To view the contents of the drive, enter:
 
Get-childitem
&nb Sp
When Windows PowerShell other drives, if you want to see an alias drive, negotiate the name of the drive before the directory, followed by a colon (:). For example,
 
Get-childitem-path alias:
&NBSP
To obtain information about a specific alias, enter the drive name and alias name, or the pattern of the name. I note: The general use of wildcard characters. For example, to get all the aliases that start with "P", enter:
 
Get-chi Lditem-path alias:p*
 
requires more information about Windows PowerShell alias provider, enter:
 
Get-help Alias-psprovider
 
  You can also refer to the
to list cmdlets for aliases, enter:
 
get-help *-alias
 
For information about functions, enter:
 
Get-help about_function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.