How to set ShowField in powershell for people picker site column

How do I set "Show Field" in PeoplePicker column to "Name" using powershell?

I've tried $siteColumn.[Show Field] ="Name",$siteColumn.'Show Field' ="Name",$siteColumn.ShowField ="Name" and $siteColumn.Show_x0020_Field ="Name" , but they are all throwing error that this property does not exist,etc


  • Edited by sanjuv Friday, February 27, 2015 10:25 AM
February 27th, 2015 10:14am

Can anyone share the code for the above , I've been looking for this but not able to find an example
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2015 4:05am

Hi,

  Use this, this one will set the show field to Email field.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$site = Get-SPSite "http://team.eworkplace.com/entity/C008"
$web=$site.OpenWeb();
$list = $web.Lists["Testing"]
$spFieldUser = [Microsoft.SharePoint.SPFieldUser]($list.Fields["Requester Name"])
$spFieldUser.LookupField = "EMail"
$spFieldUser.Update();

March 3rd, 2015 8:46am

Hi,

  Use this, this one will set the show field to Email field.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$site = Get-SPSite "http://team.eworkplace.com/entity/C008"
$web=$site.OpenWeb();
$list = $web.Lists["Testing"]
$spFieldUser = [Microsoft.SharePoint.SPFieldUser]($list.Fields["Requester Name"])
$spFieldUser.LookupField = "EMail"
$spFieldUser.Update();

Thanks for the response. Sorry for the late reply, here is my code, I tried to include in the way you told, but it does not work.

#import the csv file
     $list=Import-Csv  $csv
    
     #get sitecollection reference
     $site = Get-SPSite -Identity $siteUrl
    
     ForEach ($row in $list) {
        Try
        {
        $internamName=$row.InternalName #internal column name
        $fieldType=$row.Type #column type
        $title=$row.Title #display name of column
        
        #check if column with name and type exists in the site
        $siteColumn = $site.RootWeb.Fields | ?{($_.InternalName -eq $internamName) -and ($_.TypeAsString -eq $fieldType)};
         if($siteColumn -eq $null)
         {
          $log= " $internamName Field Not Found!"
        Write-Host  $log -foregroundcolor "yellow"
         }
         else
         {
         
           
          if($siteColumn.Type -eq "User")
           {
           Write-Host  $siteColumn.LookupField
            $siteColumn.LookupField="Name"
           }
      $siteColumn.Update($true)
          $log ="updated $title"
        Write-Host  $log
        }
        }
        Catch
        {
        $log=$_.Exception.Message
        $log= "Error:$log occured while updating $title"
        Write-Host  $log -foregroundcolor "red"
        }
        }

        
        $log= "Completed"
        Write-Host  $log -foregroundcolor "green"
        
        $site.Dispose()
 }
 



  • Edited by sanjuv Tuesday, March 03, 2015 12:26 PM
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2015 12:24pm

Hi, You must cast the site column to SPFieldUser object before you change the showfield. ...... else { if($siteColumn.Type -eq "User") { $spfieldUser=[Microsoft.SharePoint.SPFieldUser]($siteColumn) Write-Host $spfieldUser.LookupField $spfieldUser.LookupField="Name" $spfieldUser.Update() } .....
March 3rd, 2015 7:32pm

Hi, thanks for reply. I've modifed the script accordingly but when I check the showfield attribute of the site column, it still shows as "Account" instead of "Name"
Free Windows Admin Tool Kit Click here and download it now
March 4th, 2015 6:59am

Hi I don't know why it is not working, I tested this before, are you checking at list level or site column level? To propagate the changes to list you must use $spfielUser.Update(true).

Try changing to 'Title' instead of 'Name'.

March 5th, 2015 12:07am

Hi,

The following PowerShell script for your reference:

 Add-PSSnapin Microsoft.SharePoint.PowerShell
 $webURL = "<Your web url>";
 $web = Get-SPWeb $webURL;
 $mylistName = "<Your list name>";
 $mylist = $web.Lists[$mylistName];
 $mycolumn = $mylist.Fields["Modified By"];
 $mycolumn.LookupField = "Title";
 $mycolumn.Update();
 $mylist.Update();

More information is here:

Setting Show field for Person or Group type column using PowerShell

http://prasadtech2.blogspot.com/2013/10/setting-show-field-for-person-or-group.html

Best Regards,

Dennis Guo

Free Windows Admin Tool Kit Click here and download it now
March 5th, 2015 9:56pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics