Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am getting below mentioned error while executing the bold part in the script. Please help me to resolve this.
A positional parameter cannot be found that accepts argument '-DisplayName'.
+ CategoryInfo : InvalidArgument: (:) [Set-MailContact], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Set-MailContact


Hers is the script
JavaScript
$LogFile    = ‘C:\temp\Test_Purish.log’
$userscsv = Import-Csv c:\temp\user.csv;

foreach ($user in $userscsv) {
    echo $user.ACTION;    
    echo '--------------------------'; 
    $userMap=@{
                #"ACTION"="$($user.ACTION)";
                "NTDomainUID"="$($user.NTDomainUID)";
                "DisplayName"="$($user.DisplayName)";
                "KnownasGivenName"="$($user.KnownasGivenName)";
                "KnownasSn"="$($user.KnownasSn)";
                "Knownasinitial"="$($user.Knownasinitial)";
                "DivisionName"="$($user.DivisionName)";
                "DivisionCode"="$($user.DivisionCode)";
                "C"="$($user.C)";
                "PostalAddress"="$($user.PostalAddress)";
                "city"="$($user.city)";
                "St"="$($user.St)";
                "ZipCode"="$($user.ZipCode)";
                "TelephoneNumber"="$($user.TelephoneNumber)";
                "EfaxNumber"="$($user.EfaxNumber)";
                "Mobile"="$($user.Mobile)";
                "Pager"="$($user.Pager)";
                "DepartmentCode"="$($user.DepartmentCode)";
                "DepartmentName"="$($user.DepartmentName)";
                "Title"="$($user.Title)";
                "physicaldeliveryofficename"="$($user.physicaldeliveryofficename)";
                "personalAssistantDN"="$($user.personalAssistantDN)";
                "CDStatus"="$($user.CDStatus)";
                "utcManagerDN"="$($user.utcManagerDN)";
                "othertelephone"="$($user.othertelephone)";
                "exportcontrol"="$($user.exportcontrol)";
                "utcLegacyExchangeDN"="$($user.utcLegacyExchangeDN)";
                "alternatedivisioncode"="$($user.alternatedivisioncode)";
              }
    foreach($eachKey in $userMap.GetEnumerator())
    {
       <#echo $eachKey.key
       echo $eachKey.value#>
       if ($user.ACTION -eq "CREATE")
       {
            #Create new mail contact    
       }
       elseif($user.ACTION -eq "MODIFY")
       {
           if($eachKey.value.StartsWith("ADD"))
           {
                $attrKey = $eachKey.key
                $attrVal = $eachKey.value.Substring(4)                
                #Set mail contact
                #Set-MailContact -Identity $Alias -$eachKey.key '$eachKey.value';
           }
           elseif($eachKey.value.StartsWith("REPLACE"))
           {
                $uniqueKey=$user.NTDomainUID
                $attrKey = $eachKey.key
                $attrVal = $eachKey.value.Substring(8)
                echo $attrKey;
                #Set mail contact
                Set-MailContact -Identity $uniqueKey -$attrKey $attrVal;
           }
           if($eachKey.value.StartsWith("REMOVE"))
           {
                $attrVal = $eachKey.value.Substring(7)
                #Set mail contact
           }      
           Write-Output "$attrVal" | Out-File $LogFile -append
       }
    }
    
}
Posted
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900