Solved

Add Filter to For Each Powershell Script

Posted on 2015-02-21
3
99 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

Synchronize a new Active Directory domain with an existing Office 365 tenant
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

809 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