Solved

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

Posted on 2011-02-23
9
1,620 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
[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
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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)
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

733 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