Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add Filter to For Each Powershell Script

Posted on 2015-02-21
3
Medium Priority
?
166 Views
Last Modified: 2015-02-21
Hi,

I need assistance to add a filter to the following powershell script, to allow me to test only a few email addresses, before running it on our entire directory.   We can use "where the mailbox name contains "john"

$Mailboxes = get-mailbox -resultsize "unlimited"
foreach ($Mailbox in $Mailboxes) {
Set-Mailbox -Identity $Mailbox -CustomAttribute1 $Mailbox.Office
}

Open in new window

0
Comment
Question by:AD1080
[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
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 2000 total points
ID: 40623460
Use the following command...
$Mailboxes = get-mailbox -resultsize "unlimited" -filter {name -like "john*"}
foreach ($Mailbox in $Mailboxes) {
Set-Mailbox -Identity $Mailbox -CustomAttribute1 $Mailbox.Office
}

Open in new window


Will.
0
 

Author Closing Comment

by:AD1080
ID: 40623467
Thanks again.
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40623468
Not a problem, glad to help!

Will.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

597 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