Pass emty cell data for the creation of new-mailbox

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Wei-Yen Tan Wei-Yen Tan 4 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39097
    Profile photo of Frikkie Du Preez
    Frikkie Du Preez
    Participant

    Hi, I'm trying to create a script that reads data from csv and then create new mailbox in exchange 2016, Problem is not all users will have an archive and if the field is empty the shell produce the following error

    Cannot process argument transformation on parameter 'ArchiveDatabase'. Cannot convert value "" to type
    "Microsoft.Exchange.Configuration.Tasks.DatabaseIdParameter". Error: "Parameter values of type
    Microsoft.Exchange.Configuration.Tasks.DatabaseIdParameter can't be empty. Specify a value, and try again.
    Parameter name: identity"
    + CategoryInfo : InvalidData: (:) [New-Mailbox], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-Mailbox

    My script look like this
    Import-CSV CreateUserAccount.csv | ForEach-Object {New-Mailbox -Name $_.name -FirstName $_.firstname -LastName $_.surname -DisplayName $_.displayname -Alias $_.alias -OrganizationalUnit $_.parentou -samAccountName $_.samAccountName -userPrincipalName $_.userprincipalname -Database $_.mailboxdatabase -ArchiveDatabase $_.archivedatabase -Password (ConvertTo-SecureString 'Necsa123' -AsPlainText -Force) -ResetPasswordOnNextLogon $True}

    How would I alter the script so that if a user doesn't have a archive the script continue to run

    Thanks a lot for any help/replies
    F

    #39098
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    At the end -erroraction silentlycontinue

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.