Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $siteUrl = "http://bot-sp2016"
- $salesWebUrl = "SalesManagement"
- $knowledgeWebUrl = "KnowledgeBase"
- $customersListUrl = "Egrul";
- $customerFieldName = "KsupEgr_Customer"
- $sellerFieldName = "KsupSeller"
- $presaleActivityListUrl = "PresaleActivity";
- $customerSellerCtId = "0x0100E737C3D7E2C747AA8DD044E37D606A4E009D777DEF9CEB4D8E8B7937761C50A94B"
- $opBaseCtId = "0x0100E737C3D7E2C747AA8DD044E37D606A4E004A65E904D62C43AE9209A623094F1590"
- function GetReadyForSp() {
- $ver = $host | select version
- if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"}
- if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
- {
- Add-PSSnapin "Microsoft.SharePoint.PowerShell"
- }
- }
- function FindListsUsingCt($web, $ctId) {
- $foundLists = @()
- foreach($list in $web.Lists) {
- $ct = $list.ContentTypes | Where {$_.Id.ToString() -like "$ctId*" }
- if ($ct -ne $null) {
- Write-Host "[x] list found $list" -ForegroundColor Cyan
- $foundLists += $list
- }
- }
- return $foundLists
- }
- function UpdateLookupField($field, $list) {
- $field.LookupWebId = $list.ParentWeb.ID
- $field.LookupList = $list.ID
- $field.Update($false)
- }
- function RemoveFieldLookupField($field) {
- $schema = [xml]$field.SchemaXml
- $propertyToChange = $schema.Field.Customization.ArrayOfProperty.Property | Where {$_.Name -eq "ChildLookupFields"} | ForEach-Object { [void]$_.ParentNode.RemoveChild($_) }
- $field.SchemaXml = $schema.OuterXml
- $field.Update($false)
- }
- function SetFieldService($field) {
- $deleteProps = "LookingFields", "ParentLookupField"
- $schema = [xml]$field.SchemaXml
- $propertyToChange = $schema.Field.Customization.ArrayOfProperty.Property | Where {$_.Name -eq "WcfService"}
- $propertyToChange.Value.InnerText = "/_vti_bin/Portal/LanitKsupService.svc/GetItemsByTitleWithoutArchive"
- $propertyToChange = $schema.Field.Customization.ArrayOfProperty.Property | Where {$deleteProps -contains $_.Name } | ForEach-Object { [void]$_.ParentNode.RemoveChild($_) }
- $field.SchemaXml = $schema.OuterXml
- $field.Update($false)
- }
- function FixList($list, $customersList) {
- $fieldCustomer = $list.Fields | Where {$_.InternalName -eq $customerFieldName }
- $fieldSeller = $list.Fields | Where {$_.InternalName -eq $sellerFieldName}
- Write-Host "[x] fixing field $fieldCustomer" -ForegroundColor Cyan
- if($fieldCustomer) {
- UpdateLookupField -field $fieldCustomer -list $customersList
- SetFieldService -field $fieldCustomer
- } else {
- Write-Host "Skipping customer field for list $list" -ForegroundColor Red
- }
- if($fieldSeller) {
- RemoveFieldLookupField -field $fieldSeller
- } else {
- Write-Host "Skipping seller field for list $list" -ForegroundColor Red
- }
- Write-Host "[x] field fixed!" -ForegroundColor Green
- }
- GetReadyForSp
- $salesWeb = Get-SPWeb "$siteUrl/$salesWebUrl"
- $knowledgeWeb = Get-SPWeb "$siteUrl/$knowledgeWebUrl"
- $customersList = $knowledgeWeb.GetList($knowledgeWeb.Url + "/lists/$customersListUrl")
- $customerSellerLists = FindListsUsingCt -web $salesWeb $customerSellerCtId
- $opLists = FindListsUsingCt -web $salesWeb $opBaseCtId
- $allLists = $customerSellerLists + $opLists
- foreach($list in $allLists) {
- Write-Host "[x] list $list in process"
- FixList -list $list -customersList $customersList
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement