Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Getting aliases


In this recipe, we take a look at aliases in PowerShell.

How to do it...

Let's check out aliases in PowerShell:

  1. Open PowerShell ISE as an administrator.

  2. Add the following script and run it:

    #list all aliases 
    Get-Alias
    
    #get members of Get-Alias
    Get-Alias | 
    Get-Member
    
    #list cmdlet that is aliased as dir
    $alias:dir
    
    #list cmdlet that is aliased as ls
    $alias:ls
    
    #get all aliases of Get-ChildItem
    Get-Alias -Definition "Get-ChildItem"

How it works...

An alias in PowerShell is a different name that you can use for a cmdlet. Some cmdlets already come with a handful of aliases, but you can create your own aliases for cmdlets as well.

The Get-Alias returns all PowerShell aliases. PowerShell's building blocks are cmdlets that are named using the <Verb-Noun> convention. For example, to list contents of a directory, we use Get-ChildItem. There are, however, better-known ways to get this information such as dir if running the Windows Command Prompt and ls if running in a Nix environment...