?
Solved

Powershell enable-mailbox help

Posted on 2013-02-02
3
Medium Priority
?
2,440 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
In this video we show how to create a Contact 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 Recipients >> Contact ta…
In this video we show how to create a mailbox database 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 Servers >> Data…
Suggested Courses

741 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