Monday, March 21, 2016

LookUp column Web URL Changing in Using Powershell Script

 Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue
$webURL = "http://site1/"
$listName = " Card Test"
$columnName = "Designation 2"
$lookupListName = "Designation Lookup"
$lookupWebURL = "http://site"

RepairListLookupColumns -webURL $webURL -listName $listName -columnName $columnName -lookupListName $lookupListName -lookupWeb $lookupWebURL
Function RepairListLookupColumns($webURL, $listName, $columnName, $lookupListName, $lookupWebURL)
{
#Get web, list and column objects
$web = Get-SPWeb $webURL
$lookupWeb = Get-SPWeb $lookupWebURL
$lookupWeb = Get-SPWeb $lookupWebURL
$list = $web.Lists[$listName]
$column = $list.Fields[$columnName]
$lookupList = $lookupWeb.Lists[$lookupListName]
$newLookupListID = "{"+$lookupList.ID.ToString()+"}"
$newLookupWebID = "{"+$lookupWeb.ID.ToString()+"}"

#Change schema XML on the lookup column
$column.SchemaXml = $column.SchemaXml.Replace($column.LookupWebId.ToString(), $newLookupWebID)

$column.SchemaXml = $column.SchemaXml.Replace($column.LookupList.ToString(), $newLookupListID)
$column.Update()

#Write confirmation to console and dispose of web object
write-host "In Site" $web.Url "column " $column.Title "in Liste" $list.Title "is connected with"  $lookupList.Title "from" $lookupWeb.Url
$web.Dispose()
$lookupWeb.Dispose()
}


No comments:

Post a Comment