Solved

Powershell enable-mailbox help

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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.
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 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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

12 Experts available now in Live!

Get 1:1 Help Now