PowerShell Error - cannot bind argument to parameter and cannot process argument transformation

Adrian Narvaez 1 Reputation point
2022-05-18T15:55:18.55+00:00

I am trying to write a script to create journal rules for some of our users. I use a CSV file to house the journal address and their emails and names.

Here is what I have so far:

$ADUsers = Import-csv [path to csv]  
  
   foreach ($User in $ADUsers)  
{  
      
 $firstname = $User.FirstName  
 $lastname = $User.LastName  
    $email = $User.email  
 $journal = $User.journaladdress  
  
 New-JournalRule -Name "BH - $firstname $lastname" -Recipient $email -JournalEmailAddress $journal -Scope External -Enabled $True  
}  

For some reason I get these errors:

Cannot bind argument to parameter 'JournalEmailAddress' because it is null.
+ CategoryInfo : InvalidData: (:) [New-JournalRule], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,New-JournalRule
+ PSComputerName : outlook.office365.com

Cannot process argument transformation on parameter 'Recipient'. Cannot convert value "" to type
"Microsoft.Exchange.Data.SmtpAddress". Error: "The email address '' isn't correct. Please use this format: user name,
the @ sign, followed by the domain name. For example, tonysmith@Company portal .com or tony.smith@Company portal .com."
+ CategoryInfo : InvalidData: (:) [New-JournalRule], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,New-JournalRule
+ PSComputerName : outlook.office365.com

Any idea why this happens?

Exchange | Exchange Server | Management
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. KyleXu-MSFT 26,396 Reputation points
    2022-05-19T06:43:05.047+00:00

    @Adrian Narvaez
    You could use the script below:

    $ADUsers = Import-csv C:\temp\users.csv  
          
    foreach ($User in $ADUsers){      
        $JName = "BH - " + $User.FirstName + " " + $User.LastName     
        New-JournalRule -Name $JName -Recipient $User.Address -JournalEmailAddress $user.journaladdress -Scope External -Enabled $True  
    }  
    

    Here is the format of the source file (You need to change it to .CSV).

    Please note: The JournalEmailAddress can only be a mail user, a mail contact or an external address.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.