Solved

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

Posted on 2011-02-23
9
1,568 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

18 Experts available now in Live!

Get 1:1 Help Now