Solved

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

Posted on 2013-12-18
5
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Featured Post

Ready to trade in that old firewall?

Whether you need to trade-up to a shiny new Firebox or just ready to upgrade from whatever appliance you're using now, WatchGuard has the right appliance for you! Find your perfect Firebox today with appliance sizing tool!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

622 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