Solved

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

Posted on 2011-02-23
9
1,591 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
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.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

785 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