bulk add PS, from 2010 to 2013, error on initial run RRS feed

  • Question

  • Hello,

    I'm hoping this is a simple issue.  Saw the post by Mike Pfeiffer here.

    Right off the bat, I'm not a guru on scripting so although I get the basic idea of what is going on within the script, I am so far out in left field in terms of knowing what might be wrong.

    Unless I wasn't reading the post right, this is supposed to bulk add a csv list of users, assigning random passwords and creating an exchange mailbox, right?  I thought this script was perfect as the post indicates it seeks out header information that would normally be in a new mailbox request.

    Here is the particular error that I'm getting.  If somebody could help shed some light on why this is happening or if this is the start of a very large spider's web, maybe a suggestion on a similar script?


    New-Mailbox : Cannot process argument transformation on parameter 'Confirm'. Cannot convert value "System.String" to type "System.Management.Automation.SwitchParameter"
    only Boolean values and numbers, such as $True, $False, 1 or 0.
    At C:\BulkAddRandom.ps1:36 char:18
    +         if(New-Mailbox @properties)
    +                        ~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [New-Mailbox], ParameterBindingArgumentTransformationException
        + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-Mailbox

    	[Parameter(Position=0, Mandatory=$true)]
    	[Parameter(Position=1, Mandatory=$false)]
    	$PasswordLength = 8,
    	[Parameter(Position=2, Mandatory=$false)]
    	$NonAlphanumericCharacters = 0,
    	[Parameter(Position=3, Mandatory=$true)]
    begin {
    	Add-Type -AssemblyName System.Web
    	$mailboxes = Import-Csv $CSVFile
    	$props = $mailboxes | gm -MemberType NoteProperty | select -ExpandProperty Name
    	$report = @()
    process {
    	foreach($mailbox in $mailboxes) {
    		Write-Progress -Activity "Creating Mailboxes..." -Status "Progress:" -PercentComplete ($i/$mailboxes.count*100)		
    		$properties = @{}
    		$props | %{
    		$password = [System.Web.Security.Membership]::GeneratePassword($PasswordLength,$NonAlphanumericCharacters)
    		$securepassword = ConvertTo-SecureString -AsPlainText $password -Force
    		if(New-Mailbox @properties) {
    			$mailbox | Add-Member -MemberType NoteProperty -Name Password -Value $Password
    			$report += $mailbox			
    end {
    	$report | Export-Csv -Path $ReportFile -NoTypeInformation

    Tuesday, October 29, 2013 5:33 AM

All replies

  • Try to replace




    Blog -

    Tuesday, October 29, 2013 7:05 AM
  • Thanks for the fix.  That did work in getting rid of the error but after that the script would put up a fight for every AD field needed for account creation.  Not sure why but I've been searching for other import options.
    Wednesday, October 30, 2013 2:31 AM
  • >> the script would put up a fight for every AD field needed for account creation

    Which properties in particular are you getting errors with ?

    You might be better expanding out that script so you assign each variable separately in New-Mailbox.

    eg New-Mailbox -UserPrincipalName $mailbox.UserPrincipalName -Alias $mailbox.Alias

    This just makes it easier to debug as you can see what's going in and in what order and you can compare it to what you run for one user manually.





    Wednesday, October 30, 2013 4:00 AM
  • That is actually what I found, a spelled out version. 

    Initially I thought this script was great since it appeared to require almost no editing, reading all the fields (assuming they were correct) from the csv file.

    I don't quite remember the exact errors, but they were aimed at the new-mailbox command getting real cranky with some of the basic required fields.  I had checked the fields down to the spelling, even looking at what ADSI was pulling up and still errors. 

    Anyway, I am taking the reverse approach now of creating the AD account, then I'll mail enable.

    Wednesday, October 30, 2013 4:51 AM