Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBook
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
Exchange Server 2007
»
New-IEXMailboxFromCsv
New-IEXMailboxFromCsv
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
.NET Framework
address list
cluster
database
distribution group
email
email address
Exchange
Exchange 2007
export
filter
get
Get-Queue
mailbox
Mailbox Size
new
pst
Quota
remove
space
statistics
test
tip
user
validity
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
ps1
09-23-2009
Downloads: 270
File size: 2.9kB
Views: 566
Embed
New-IEXMailboxFromCsv
## =====================================================================
## Title
: New-IEXMailboxFromCsv
## Description : Create mailbox using data from CSV file.
## Author
: Idera
## Date
: 09/15/2009
## Input
:
New-IEXMailboxFromCsv [[-CsvFilePath] <String>] [-ResetPasswordOnNextLogon] [-WhatIf] [-Confirm]
##
## Output
: Microsoft.Exchange.Data.Directory.Management.Mailbox
## Usage
:
##
1. Check what would happen if you try to create mailboxes using c:\users.csv as input file.
##
New-IEXMailboxFromCsv -CsvFilePath c:\users.csv -WhatIf
##
##
2. Create mailboxes using data from c:\users.csv, set "User must change password at next log on", and ask for confirmation.
##
New-IEXMailboxFromCsv -CsvFilePath c:\users.csv -ResetPasswordOnNextLogon -Confirm
##
## Notes
:
## Tag
: Exchange 2007, mailbox, create
## Change log
:
## =====================================================================
## sample CSV file
# Name,SamAccountName,Password,FirstName,LastName,Database,OrganizationalUnit
# Test1,Test1,P@ssw0rd,Test,User1,Mailbox Database,"domain.com/users"
# Test2,Test2,P@ssw0rd,Test,User2,Mailbox Database,
# Test3,Test3,P@ssw0rd,Test,User3,Mailbox Database,"cn=users,dc=domain,dc=com"
#requires -pssnapin Microsoft.Exchange.Management.PowerShell.Admin
function
New-IEXMailboxFromCsv
{
param
(
[
string
]
$CsvFilePath
=
$
(Throw
"Parameter 'CsvFilePath' cannot be empty"
),
[
switch
]
$ResetPasswordOnNextLogon
,
[
switch
]
$WhatIf
,
[
switch
]
$Confirm
)
trap
{
Write-Error
$_
continue
}
if
(
Test-Path
-Path
$CsvFilePath
-PathType
Leaf)
{
$DomainFQDN
=
([
ADSI
]
""
).
distinguishedName
-replace
'dc='
-replace
','
,
'.'
Import-Csv
-Path
$CsvFilePath
|
Foreach-Object
{
$line
=
$_
if
(
!
$_
.
OrganizationalUnit
) {
Write-Warning
"OU name was not specified, '$DomainFQDN/Users'
will be used ins."
$_
.
OrganizationalUnit
=
"$DomainFQDN/Users"
}
$db
=
Get-MailboxDatabase
|
Where-Object
{
$_
.
Name
-eq
$line
.
Database
}
if
(
!
$db
)
{
Throw
"Database '$Database' could not be found"
}
$Pwd
=
ConvertTo-SecureString
-
String
$_
.
Password
-AsPlainText
-Force
$UPN
=
"{0}@$DomainFQDN"
-f
$_
.
name
New-Mailbox
-Name
$_
.
Name
-FirstName
$_
.
FirstName
-LastName
$_
.
LastName
-SamAccountName
$_
.
SamAccountName
-Password
$Pwd
-Database
$db
-UserPrincipalName
$UPN
-OrganizationalUnit
$_
.
OrganizationalUnit
-ResetPasswordOnNextLogon
:([
bool
]
$ResetPasswordOnNextLogon
)
-WhatIf
:
$WhatIf
-Confirm
:
$Confirm
}
}
else
{
Throw
"File: '$CsvFilePath' cannot be found"
}
}
Filed under:
Exchange 2007
,
mailbox
,
create
Create mailbox using data from CSV file.
Copyright 2011 PowerShell.com. All rights reserved.