Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

bulk AD and mailbox creation failing in CSV

$
0
0

i'm trying to create multiple accounts for Exchange and have this script:

Import-Module ActiveDirectory
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto
import-csv "c:\sunrise2.csv" -header ("Alias","FirstName","LastName","Name","UPN","OUpath","MDB","Description","Title","Password") | foreach-object {
  $Password = convertto-securestring $_.Password -asplaintext -force
  new-mailbox -name $_.Name -alias $_.Alias -FirstName $_.FirstName -LastName $_.LastName -userPrincipalName $_.UPN -MBDB $_.MDB -OrganizationalUnit $_.OUpath -Password $Password –ResetPasswordOnNextLogon:$false -description $_.Description -title $_.Title
}

when I don't include the "-header" parameter in the import-csv command I get this:

Import-Csv : Cannot process argument because the value of argument "name" is invalid. Change the value of the "name" argument and run the operation again.
At D:\Documents\sunrise.ps1:5 char:11
+ import-csv <<<<  "c:\sunrise2.csv"  | foreach-object {
    + CategoryInfo          : InvalidArgument: (:) [Import-Csv], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ImportCsvCommand

when I do include the "-header" parameter, I get this:

New-Mailbox : Cannot bind argument to parameter 'Name' because it is an empty string.
At line:3 char:20
+   new-mailbox -name <<<<  $_.Name -alias $_.Alias -FirstName $_.FirstName -LastName $_.LastName -userPrincipalName $_.UPN -MBDB $_.MDB -OrganizationalUnit $_.OUpath -Password $Password –Res
etPasswordOnNextLogon:$false -description $_.Description -title $_.Title
    + CategoryInfo          : InvalidData: (:) [New-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Exchange.Management.RecipientTasks.NewMailbox

so I try to isolate the problem by running the commands one line at a time. seems odd that the first output would return the value of the headers:

Alias       : Alias
FirstName   : FirstName
LastName    : LastName
Name        : Name
UPN         : UPN
OUpath      : OUpath
MDB         : MDB
Description : Description
Title       : Title
Password    : Password

when I run this:

import-csv "c:\sunrise2.csv" -header ("Alias","FirstName","LastName","Name","UPN","OUpath","MDB","Description","Title","Password")

i'm kinda stuck now how to proceed because of that header thing.

appreciate any help.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>