Solved

what does this mean? {$_.S   -q  } Help with the script

Posted on 2013-12-18
5
328 Views
Last Modified: 2013-12-23
what does this mean? {$_.S   -q  } I see it all the time in the scripts. For example
-ResultSize unlimited | Where {$_.Subject -eq "System Alert: Sales Database Reaching Capacity"} | Remove-Message -WithNDr $False



 I would like to be able to write simple scripts in powershell for Exchange 2010 &2013. Could you please advice on the good resource or videos that I can use.

Thank you very much!
0
Comment
Question by:claudiamcse
5 Comments
 
LVL 1

Assisted Solution

by:Rapska1ion
Rapska1ion earned 167 total points
ID: 39728366
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 167 total points
ID: 39728468
Hi,

-ResultSize unlimited | Where {$_.Subject -eq "System Alert: Sales Database Reaching Capacity"} | Remove-Message -WithNDr $False

Open in new window


The "|" means that it is piping / pipelining objects from left to the right - but instead of generating a bunch of variables it is directly passing the objects down.

So the above means to get "all" results, then setting a filter on the resultset where the subject of each element equals "System ..." and these filtered resultset is going to be deleted (item by item). WithNDR parameter specifies whether a non-delivery report (NDR) is returned to the sender of a message. The default value is $true, therefore it is set here to false.

A good starting point for Exchange PSHell is here:
http://exchangeserverpro.com/powershell/
(of course the above training is very important as you should already know the basics of PS before digging into a specific server management and administration)

HTH
Rainer
0
 
LVL 57

Assisted Solution

by:Mike Kline
Mike Kline earned 166 total points
ID: 39728905
I was going to try and explain it but my friend Mark Minasi recently wrote a column and he did a great job

http://windowsitpro.com/powershell-amp-scripting/where-object-and-pipeline

I like Mark's idea think of $_ as $pipeline. Let me know if you questions after reading Mark's article

For training definitely start the free Microsoft Virtual Academy courses on powershell

http://www.microsoftvirtualacademy.com/Studies/SearchResult.aspx?q=powershell#?fbid=zc-AfodZCsj

They are taught by the inventor of powershell.  There are a lot of other great resources but start there and look at Mark's old columns too.  You will also get better the more you practice.

Thanks

Mike
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 39732027
Quick answer - Think of anything starting with "$_." being an input variable. So if you are pulling in a CSV file to do stuff in powershell, and your CSV looks like:

Name, JobTitle
smithj, manager
williamsa, IT supervisor
johnsonk, engineer

So then to grab the values, you would use "$_.Name" and "$_.JobTitle"

"-eq" stands for equal.
0
 

Author Closing Comment

by:claudiamcse
ID: 39737007
Thanks a lot!!!
0

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now