Solved

Powershell enable-mailbox help

Posted on 2013-02-02
3
2,317 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 500 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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).
In this video we show how to create an email address policy 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 Mail Flow…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

730 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