Solved

Powershell enable-mailbox help

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
To show how to create a transport rule 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 >> Rules tab.:  To cr…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now