Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

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

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
claudiamcse
Asked:
claudiamcse
3 Solutions
 
Rapska1ionCommented:
0
 
Rainer JeschorCommented:
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
 
Mike KlineCommented:
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
 
ThinkPaperCommented:
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
 
claudiamcseAuthor Commented:
Thanks a lot!!!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now