Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PowerShell
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: (Smile | :) [Set-MailContact], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Set-MailContact
 

Hers is the script
$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 21-Mar-13 1:01am
Edited 21-Mar-13 1:07am
(no name)117.6K
v2

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

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100