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