Powershell - Alias
JASON
Cmdlet


(Get-Command –type Cmdlet).Length
Get-Command


The Get-Command cmdlet gets all commands that are installed on
the computer, including cmdlets, aliases, fu...
Powershell Alias - Abbreviation


Get → g



Set → s



Item → i



Location → l



Command → cm



Get-Item → gi

...
New-Alias


New-Alias [-Name] <string> [-Value] <string>


Example : New-Alias log Write-Host



Aliases created by usi...
Get-Alias


The Get-Alias cmdlet gets the aliases in the current session.



This includes built-in aliases, aliases tha...
Modify Alias


Example 1:




Example 2:




New-Alias log Write-Verbose –Force

Set-Alias log Write-Verbose

Example...
Getting to the Alias: Drive


This command changes the current location to the Alias: drive



To return to a file syste...
PowerShell Drive


We connect to PowerShell Providers by mounting the Providers
PowerShell Drive(PSDrive)
Delete Alias


Use Remove-Item (del) cmlet



Example :


PS C:UsersJason> cd alias:



PS Alias:> del log



PS C:Us...
Export-Alias


The Export-Alias cmdlet exports the aliases in the current session to a
file.



Example 1: Export-Alias ...
Export-Alias


Export-Alias aliases.txt
Export-Alias


Export-Alias aliases.ps1 -as Script
Import-Alias


The Import-Alias cmdlet imports an alias list from a file.



Beginning in Windows PowerShell 3.0, as a s...
Q1


Get-ChildItem *.txt | Where-Object { $_.Length –gt 5KB } | ForEachObject { $_.Name }



Gci *.txt | ? { $_.Length –...
Q2


是否可以建立一個為 「Get-Command」的別名??



Example:


New-Alias Get-Command dir
Reference


TechNet


http://technet.microsoft.com/en-us/library/ee176913.aspx
Upcoming SlideShare
Loading in...5
×

Powershell alias

232

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
232
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • wildcard 
  • Gci *.txt | ? { $_.Length –gt 5KB } | % { $_.Name }
  • Powershell alias

    1. 1. Powershell - Alias JASON
    2. 2. Cmdlet  (Get-Command –type Cmdlet).Length
    3. 3. Get-Command  The Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, workflows, filters, scripts, and applications.  Example : Get-Command -CommandType Alias g*
    4. 4. Powershell Alias - Abbreviation  Get → g  Set → s  Item → i  Location → l  Command → cm  Get-Item → gi  Set-Item → si  Get-Location → gl  Get-Command → gcm
    5. 5. New-Alias  New-Alias [-Name] <string> [-Value] <string>  Example : New-Alias log Write-Host  Aliases created by using New-Alias are not saved after you exit the session or close Windows PowerShell  You can use the Export-Alias cmdlet to save your alias information to a file  You can later use Import-Alias to retrieve that saved alias information.
    6. 6. Get-Alias  The Get-Alias cmdlet gets the aliases in the current session.  This includes built-in aliases, aliases that you have set or imported, and aliases that you have added to your Windows PowerShell profile.  Example : Get-Alias l*  Example : if(Get-Alias log) { log “Alias Exists” }
    7. 7. Modify Alias  Example 1:   Example 2:   New-Alias log Write-Verbose –Force Set-Alias log Write-Verbose Example 3:    cd Alias: Set-Item log Write-Verbose Example 4:  cd Alias:  Set-Content log Write-Verbose
    8. 8. Getting to the Alias: Drive  This command changes the current location to the Alias: drive  To return to a file system drive, type the drive name. For example, type "set-location c:".  Example :  PS C:UsersJason> cd alias:  PS Alias:> dir l*
    9. 9. PowerShell Drive  We connect to PowerShell Providers by mounting the Providers PowerShell Drive(PSDrive)
    10. 10. Delete Alias  Use Remove-Item (del) cmlet  Example :  PS C:UsersJason> cd alias:  PS Alias:> del log  PS C:UsersJason> Remove-Item alias: log
    11. 11. Export-Alias  The Export-Alias cmdlet exports the aliases in the current session to a file.  Example 1: Export-Alias aliases.txt  Example 2 : Export-Alias aliases.txt log*  Example 3 : Export-Alias aliases.txt trace* -append  Example 4 : Export-Alias aliases.ps1 trace* -as Script
    12. 12. Export-Alias  Export-Alias aliases.txt
    13. 13. Export-Alias  Export-Alias aliases.ps1 -as Script
    14. 14. Import-Alias  The Import-Alias cmdlet imports an alias list from a file.  Beginning in Windows PowerShell 3.0, as a security feature, ImportAlias does not overwrite existing aliases by default.  To overwrite an existing alias, after assuring that the contents of the alias file is safe, use the Force parameter.  Example : Import-Alias aliases.txt
    15. 15. Q1  Get-ChildItem *.txt | Where-Object { $_.Length –gt 5KB } | ForEachObject { $_.Name }  Gci *.txt | ? { $_.Length –gt 5KB } | % { $_.Name }
    16. 16. Q2  是否可以建立一個為 「Get-Command」的別名??  Example:  New-Alias Get-Command dir
    17. 17. Reference  TechNet  http://technet.microsoft.com/en-us/library/ee176913.aspx
    1. Gostou de algum slide específico?

      Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

    ×