Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Microsoft Exchange Server PowerShell Essentials
  • Table Of Contents Toc
  • Feedback & Rating feedback
Microsoft Exchange Server PowerShell Essentials

Microsoft Exchange Server PowerShell Essentials

By : Banerjee
5 (3)
close
close
Microsoft Exchange Server PowerShell Essentials

Microsoft Exchange Server PowerShell Essentials

5 (3)
By: Banerjee

Overview of this book

PowerShell has become one of the most important skills in an Exchange administrator's armory. PowerShell has proved its mettle so widely that, if you're not already starting to learn PowerShell, then you're falling behind the industry. It isn't difficult to learn PowerShell at all. In fact, if you've ever run commands from a CMD prompt, then you'll be able to start using PowerShell straightaway. This book will walk you through the essentials of PowerShell in Microsoft Exchange Server and make sure you understand its nitty gritty effectively. You will first walk through the core concepts of PowerShell and their applications. This book discusses ways to automate tasks and activities that are performed by Exchange administrators and that otherwise take a lot of manual effort. Microsoft Exchange PowerShell Essentials will provide all the required details for Active Directory, System, and Exchange administrators to help them understand Windows PowerShell and build the required scripts to manage the Exchange Infrastructure.
Table of Contents (12 chapters)
close
close
11
Index

Using filters and exporting data

In order to understand how powerful Windows PowerShell is, you need to look at the filtering capabilities it offers. With an understanding of objects and pipelining, you can retrieve the exact information you are looking for. The Usage of Pipeline section talks about how pipelines can be used to pass one or more objects, which are the output of one command, and feed them into another cmdlet. In Windows PowerShell, there are commands that will help you to refine and get the desired output. Some of these cmdlets that we will look in this section are Where-Object, Sort-Object, Select-Object, and Select-String.

The Where-Object cmdlet helps you to filter the output returned by other cmdlets. For example, the Get-service cmdlet without any parameter retrieves information about the services installed on the computer on which it is called:

Using filters and exporting data

Now, let's filter the output of Get-Service to find the list of services that are stopped:

Using filters and exporting data

Windows PowerShell supports the following logical operators that we are going to use in our next example of filtering the output of a Get-Service cmdlet:

Operator

Description

-and

This is true only when both statements are true

-or

This is true when either or both statements are true

-xor

This is true if one condition is true and the other one is false

-not

The statement followed by this operator is negated

!

This is the same as the –not operator

We will now find services that are running whose name starts with Windows using the –and operator:

Using filters and exporting data

By default, Windows PowerShell will sort the output of commands using an alphabetical order. You can then use the Sort-object cmdlet to sort it using any way you like. For example, the following example will first sort the output of the Get-Process cmdlet by the Process ID and then the CPU time:

Using filters and exporting data

At times, you might need to filter your results based on certain specific property names. This is where the Select-Object cmdlet comes in handy. It selects the stated properties of a single or group of objects. You can use Select-Object to select objects that are unique in a group of objects It supports parameters such as First, Last, Skip, and Index. You can select one or multiple object properties using the –Property parameter. Let's take an example of the output of the Get-Process cmdlet, and let's say you are troubleshooting a performance issue on a server and are only interested to know about the CPU time and process name properties. The output of the Get-Process cmdlet will be piped to Select-Object with the –property parameter set to the process name and CPU. The Format-list cmdlet will format the output displayed in the console:

PS C:\> Get-Process | Select-Object -Property Processname, CPU | format-list

Now, let's use another parameter called –Unique of Select-Object. This will select a single member from a number or objects with same properties and values. In the following example, you will notice that the –Unique parameter is case sensitive and reports "c" and "C" as unique.

Using filters and exporting data

Another useful filtering cmdlet is Select-String, used to select text patterns in strings and files. If you are familiar with UNIX shells, it is used as Grep or Findstr in Windows. It can display all the matches or stop after the first match depending on the usage of the cmdlet. You can search files of Unicode text using this command as well.

First, we will create a file using the redirection operator (>) to store the list of services running on a server to a text file:

PS C:\> Get-Service > service.txt

Now, we will find the text "Network" and "Windows" to get a list of all the services that have the word in it. We will then use the –notmatch parameter to list all the services except this word:

Using filters and exporting data

Note that the search performed here is a case insensitive search; you can use the —case sensitive parameter to make it case sensitive, which means you won't get any output if you use the parameter with the previous command as there are no matches found.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Microsoft Exchange Server PowerShell Essentials
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon