2

I'm writing a foreach loop script I've done this before but this script is giving me a problem. It works when I manually enter the name but when I try and pull from a txt file I get errors.

$mailboxes = Get-Mailbox joerod

foreach ($mailbox in $mailboxes) 
 { 
 $user = $mailbox.alias 
 Write-Host "Processing... $user" 
 $mailbox.EmailAddresses += [Microsoft.Exchange.Data.CustomProxyAddress] ("X500:/o=OrgName/ou=First Administrative Group/cn=Recipients/cn=$user") 
 Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses 
 } 
3
  • You need to be lot clearer and more specific. Manually enter what name, and how? Pull from a text file how? What errors are you getting? (Don't describe them, post them) Commented Nov 27, 2013 at 19:51
  • I was trying to pull from a text using get-content and it was not working, it would use the first user name and try and join it to other names. Commented Nov 27, 2013 at 19:58
  • my question was how do I run through a list of names and insert each name after Get-Mailbox Commented Nov 27, 2013 at 20:05

1 Answer 1

1

Added the following line and got what I was looking for

$mailboxes = Get-Mailbox -OrganizationalUnit "ou=users,dc=contoso,dc=local"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.