Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Exchange Server 2016 PowerShell Cookbook

You're reading from   Microsoft Exchange Server 2016 PowerShell Cookbook Powerful recipes to automate time-consuming administrative tasks

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher
ISBN-13 9781787126930
Length 648 pages
Edition 4th Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Mike Pfeiffer Mike Pfeiffer
Author Profile Icon Mike Pfeiffer
Mike Pfeiffer
Nuno Filipe M Mota Nuno Filipe M Mota
Author Profile Icon Nuno Filipe M Mota
Nuno Filipe M Mota
Nuno Mota Nuno Mota
Author Profile Icon Nuno Mota
Nuno Mota
Jonas Andersson Jonas Andersson
Author Profile Icon Jonas Andersson
Jonas Andersson
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. PowerShell Key Concepts FREE CHAPTER 2. Exchange Management Shell Common Tasks 3. Managing Recipients 4. Managing Mailboxes 5. Distribution Groups and Address Lists 6. Mailbox Database Management 7. Managing Client Access 8. Managing Transport Servers 9. Exchange Security 10. Compliance and Audit Logging 11. High Availability 12. Monitoring Exchange Health 13. Integration 14. Scripting with the Exchange Web Services Managed API 15. Common Shell Information 16. Query Syntaxes

Command aliases

Throughout this book and previous books, we have referred to command aliases or cmdlet aliases: for example, the short name of the full cmdlet.

These aliases can be very handy when writing scripts where you might want to optimize and keep them as small and as short as possible.

Let us take a look at some examples of the built-in aliases. For example, we have the cmdlet Where-Object, which is commonly used. We have two aliases for it, which are? or where. Another example on a regularly used cmdlet would be ForEach-Object; there are two aliases for it and those are % or foreach. The last example of a built-in alias is for the cmdlet Select-Object, where the alias is select.

How to do it...

When running a PowerShell command, instead of using the full cmdlet, we can create aliases for them. Let's have a look at a few examples of how to utilize the aliases:

    Get-Alias
    
New-Alias -Name wh -Value Write-Host
wh "Testing alias"

New-Alias -Name list -Value Get-ChildItem
list -Path "C:\Scripts"

New-Alias -Name npp -Value "C:\Program Files ` (x86)\Notepad++\notepad++.exe"
npp

How it works...

We start off with using the Get-Alias cmdlet. With the cmdlet, we will list all current aliases. If you haven't created any custom aliases only the built-in aliases are listed.

In the preceding examples, we have three different aliases created. Aliases could be created for cmdlets that you are using frequently or if you want to be able to launch an application using an alias directly from the PowerShell prompt.

The first example is set to wh, which is an alias for Write-Host. We can use this by type in wh "Testing alias", and the Write-Host cmdlet should be utilized in the background and show us the text on screen.

In our second example, we have to create an alias for Get-ChildItem; the alias we create for it is list. We can then get started to use list -Path "C:\Scripts" to retrieve all the files and folders from the folder C:\Scripts.

The third and final example is to create an alias for launching the Notepad++ application. This is simply done by setting the value of the alias to the full path to the .exe file of the application. Once it's done, you can from the PowerShell prompt, you can simply type in npp for launching Notepad++.

See also

  • The Setting up a PowerShell profile recipe in this chapter
  • The Working with variables and objects recipe in this chapter
  • The Looping through items recipe in this chapter
You have been reading a chapter from
Microsoft Exchange Server 2016 PowerShell Cookbook - Fourth Edition
Published in: Jul 2017
Publisher:
ISBN-13: 9781787126930
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image