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

x
?
Solved

Powershell enable-mailbox help

Posted on 2013-02-02
3
Medium Priority
?
2,532 Views
Last Modified: 2013-02-02
I am struggling to do something in Powershell which I imagine should be relatively straightforward.  I have existing user accounts in a particular OU in AD, I now just want to enable mailboxes for these accounts.  I've been trying several variations of trying to pipe get-aduser to enable-mailbox but I just can't get it to work.

Basically the tactic I have been trying is:

$users = get-user -organizationalunit 'OU=TestOU,DC=company,DC=local'
$users | foreach ( $_ ) { enable-mailbox $users.identity -database Database }

I get the error:  "Cannot process argument transformation on parameter 'identity'. Cannot convert the "system.collections.arraylist" value of type "system.collections.arraylist" to type "microsoft.exchange.configuration.tasks.useridparameter"

If I set $users to = get-aduser -searchbase 'OU=TestOU,DC=company,DC=local' -filter *

and then try:

$users | foreach ( $_ ) { enable-mailbox $users.useridparameter -database Database }

I get an error saying 'Cannot bind argument to parameter 'identity' because it is null'

Anyone have any ideas?
0
Comment
Question by:Riana
[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
3 Comments
 
LVL 5

Accepted Solution

by:
coraxal earned 2000 total points
ID: 38846543
You're on the right path, but your ForEach-Object cmdlet is setup incorrectly. You don't have to use parentheses when you're piping an array. The script should look something like this:
$users = Get-ADUser -Filter * -searchbase 'OU=TestOU,DC=company,DC=local'
$database = "Your Database Name Here"
$users | ForEach-Object { enable-mailbox $_.DistinguishedName -database $database }

Open in new window

Or, you could use a different variation like this:
$users = Get-ADUser -Filter * -searchbase 'OU=TestOU,DC=company,DC=local'
$database = "Your Database Name Here"

foreach ($user in $users)
{
	enable-mailbox $user.DistinguishedName -database $database
}

Open in new window

0
 
LVL 4

Expert Comment

by:Smighty
ID: 38846769
do the whole process with the GUI and then look at the Powershell output...
0
 

Author Closing Comment

by:Riana
ID: 38846877
Perfect, many thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

610 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