?
Solved

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

Posted on 2011-02-23
9
Medium Priority
?
1,694 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
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 …
Suggested Courses

649 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