Solved

Powershell: "New-Mailbox" Syntax - how to disable account

Posted on 2011-02-23
9
1,584 Views
Last Modified: 2012-06-27
Experts,

I am fairly new to Powershell, and am currently have a working script that grabs information out of a CSV file and creates the user account and mailbox. The problem is, that since these accounts are not supposed to be in use yet, I need to have them disabled upon creation. It seems I am not getting the syntax correctly. Can anyone help me out?

The below commands work fine, but I am having issues with the "-AccountDisabled" command, which I THOUGHT I could use to disable the account.

I have tried:

-AccountDisabled $true
-AccountDisabled "True"

and these returns an error
THIS WORKS:
=====================================
Import-CSV "c:\Scripts\test.csv" | ForEach {New-Mailbox -Alias $_.alias -Name $_.name -FirstName #_.fn -userPrincipalName $_.UPN -Database "exchsvr\Exchange Mailbox Database (A-K)" -OrganizationalUnit "Imported Users" -Password $Password -ResetPasswordOnNextLogon $true}

THIS DOES NOT WORK:
========================================
Import-CSV "c:\Scripts\test.csv" | ForEach {New-Mailbox -Alias $_.alias -AccountDisabled $true -Name $_.name -FirstName #_.fn -userPrincipalName $_.UPN -Database "exchsvr\Exchange Mailbox Database (A-K)" -OrganizationalUnit "Imported Users" -Password $Password -ResetPasswordOnNextLogon $true}

Open in new window

0
Comment
Question by:ThinkPaper
  • 5
  • 4
9 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34964986
THIS WORKS: 
===================================== 
Import-CSV "c:\Scripts\test.csv" | ForEach {New-Mailbox -Alias $_.alias -Name $_.name -FirstName #_.fn -userPrincipalName $_.UPN -Database "exchsvr\Exchange Mailbox Database (A-K)" -OrganizationalUnit "Imported Users" -Password $Password -ResetPasswordOnNextLogon $true} 
 
THIS DOES NOT WORK: BUT THIS DOES :P
======================================== 
Import-CSV "c:\Scripts\test.csv" | ForEach {New-Mailbox -Alias $_.alias -AccountDisabled -Name $_.name -FirstName #_.fn -userPrincipalName $_.UPN -Database "exchsvr\Exchange Mailbox Database (A-K)" -OrganizationalUnit "Imported Users" -Password $Password -ResetPasswordOnNextLogon $true}

Open in new window

0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34965004
-AccountDisabled does NOT take a true or false param. It is a flag in its owb right.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34965006
owb=own
0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 34970065
I have tried -AccountDisabled by itself and it doesn't seem to work... I get no error though, but when I hit <enter> after the command, it seems to wait for further commands, with the ">>"

[PS] c:\> Import-CSV "c:\Scripts\test.csv" | ForEach {New-Mailbox -Alias $_.alias -AccountDisabled -Name $_.name -FirstName #_.fn -userPrincipalName $_.UPN -Database "exchsvr\Exchange Mailbox Database (A-K)" -OrganizationalUnit "Imported Users" -Password $Password -ResetPasswordOnNextLogon $true}
>>
 
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 37

Expert Comment

by:Neil Russell
ID: 34970472
-FirstName #_.fn
Should be $_.fn i think....
0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 34973315
Thanks, yeah I caught that, it was a typo but it's still not working
0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 34973353
Error given now:

New-Mailbox: A parameter cannot be found that matches parameter name 'AccountDisabled'.

(with some other info afterwards showing the line it errors out on, etc)

+ CategoryInfo :InvalidArugment: (:[New-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId: NamedParameterNotFound,Microsoft.Exchange.Management.REcipientTasks.NewMailbox
0
 
LVL 16

Accepted Solution

by:
ThinkPaper earned 0 total points
ID: 34998018
Well.. I never got the command working. So now I just simply went into AD and selected the accounts and disabled them that way. Still, it would be nice to use powershell to disable them immediately... =/
0
 
LVL 16

Author Closing Comment

by:ThinkPaper
ID: 35042496
Well.. I never got the command working. So now I just simply went into AD and selected the accounts and disabled them that way. Still, it would be nice to use powershell to disable them immediately...
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

26 Experts available now in Live!

Get 1:1 Help Now