Solved

Add Filter to For Each Powershell Script

Posted on 2015-02-21
3
87 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
Comment Utility
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
Comment Utility
Thanks again.
0
 
LVL 53

Expert Comment

by:Will Szymkowski
Comment Utility
Not a problem, glad to help!

Will.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

763 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

12 Experts available now in Live!

Get 1:1 Help Now