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
Solved

Add Filter to For Each Powershell Script

Posted on 2015-02-21
3
103 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
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

790 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