PowerShell實現基於SharePoint的網站HomePage Auto-Configure Solution

Home Page Web Parts Auto-Configuration

PS:該項目爲公司項目,我仍是給他的名字屏蔽掉吧,這是我用PowerShell寫的一個自動化升級工具,此爲三部自動化工具的第三部,是用PowerShell配置SharePoint頁面的web parts' settings以及生成相關的SharePoint數據以支持web part的正常工做。web

Prerequisite:

本次內容爲*** Home Page自動部署三步中最後一步,將完成*** HomePage主Jira上「HomePage各web part配置文檔」中第九步以後的全部關於配置web part的相關內容。api

General:

自動配置My Documents web part settingside

自動配置Site Management web part settings工具

自動配置My Tasks web part settingsui

                自動建立Scanned Documents所須要的Task List並命名爲「***Tasks」.net

自動配置Administration web part settingsorm

自動配置Quick Links web part settingsip

                自動建立Quick Links web part所關聯的Links Listci

自動生成Title,Description,Order,RedirectURL,RedirectMethod五個column文檔

自動添加五種column到All Items view下

*因爲Workflow屬用戶第三方Service,因此本次配置中並不包含Workflow相關。

Method:Right click and run it with PowerShell.

#This third solution should be used after the second solution which keeps a name of "HomePage Auto-Create"

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Write-Host "Initializing..."

$Time = Get-Date

$Today = $Time.year.toString() + "." + $Time.month.toString() + "." + ($Time.day-1).toString()

$siteURL = "https://teamsite.migration.net/sites/" + $Today + ".HomePage"

$HomePageURL = "https://teamsite.migration.net/sites/" + $Today + ".HomePage/Pages/***HomePage.aspx"

$HomePageSiteCollection = Get-SPSite -Identity $siteURL

$HomePageWeb = $HomePageSiteCollection.rootweb

$HomePagePubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($HomePageWeb)

$HomePage = $HomePagePubWeb.GetPublishingPage($HomePageURL)

Write-Host "Begin to configure the HomePage web parts..."

$HomePage.CheckOut()

$HomePageWeb.AllowUnsafeUpdates = $true

$limitedWebPartManager = $HomePage.ListItem.File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

#Modify the configuration information of the My Documents web part.

Write-Host "Begin to configure the My Documents web part..."

$MyDocumentsWebPart = $limitedWebPartManager.WebParts|where{$_.DisplayTitle -like '*My Documents*'}

$MyDocumentsWebPart.SearchServiceName = "SharePoint_Search_Proxy_***"

$MyDocumentsWebPart.DataBaseName = "DocAve6_ReportDB_***"

$MyDocumentsWebPart.ServerName = "***DB"

$MyDocumentsWebPart.Description = "Document Management Web Part"

$MyDocumentsWebPart.ChromeType = "TitleOnly"

#Modify the configuration information of the Site Management web part.

Write-Host "Begin to configure the Site Management web part..."

$SiteManagementWebPart = $limitedWebPartManager.WebParts|where{$_.DisplayTitle -like '*Site Management*'}

$SiteManagementWebPart.DataBaseName = "DocAve6_ReportDB_***"

$SiteManagementWebPart.ServerName = "***DB"

$SiteManagementWebPart.SearchServiceName = "SharePoint_Search_Proxy_***"

$SiteManagementWebPart.ChromeType = "TitleOnly"

#Modify the configuration information of the My Tasks web part.

Write-Host "Begin to configure the My Tasks web part..."

$MyTasksWebPart = $limitedWebPartManager.WebParts|where{$_.DisplayTitle -like '*Task*'}

$MyTasksWebPart.ChromeType = "TitleOnly"

#Create the task list

#$HomePageWeb.ListTemplates|where{$_.name -like 'tasks'}

Write-Host "Begin to create the tasks list with the name of '***Tasks' to work for the scanned documents module..."

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Tasks

$ListCollection = $HomePageWeb.Lists

$ListCollection.Add("***Tasks","Work for *** HomePage My Tasks web part.",$listTemplate)

$ListCollection.Update()

$TasksList = $HomePageWeb.Lists|where{$_.title -like '***Tasks'}

$TasksList.OnQuickLaunch = "True"

$TasksList.Update()

#Scanned Documents settings

Write-Host "Begin to configure the Scanned Documents module..."

$MyTasksWebPart.ScanDocument_Title = "Scanned Documents"

$MyTasksWebPart.ScanDocument_LinkScript = "#"

#Service Catalogue settings

Write-Host "Begin to configure the Service Catalogue module..."

$MyTasksWebPart.ServiceCatalogue_Title = "Service Catalogue"

$MyTasksWebPart.ServiceCatalogue_Link = "#"

#Workflow settings

Write-Host "Begin to configure the Workflow module(Only basic)..."

$MyTasksWebPart.Workflow_Title = "Workflow"

$MyTasksWebPart.Workflow_Link = "#"

#SS settings

Write-Host "Begin to configure the Target for the scanned documents module..."

$MyTasksWebPart.SS_TargetWebUrl = $siteURL

$MyTasksWebPart.SS_TargetListName = "***Tasks"

$MyTasksWebPart.SS_RequestRootUrl_SC = "https://***damanager.migration.net:15999"

#Create the Links list

#$HomePageWeb.ListTemplates|where{$_.name -like 'tasks'}

Write-Host "Begin to create the Links list to work for the Quick Links web part..."

$listTemplate = $HomePageWeb.ListTemplates|where{$_.name -like 'custom list'}

$ListCollection = $HomePageWeb.Lists

$ListCollection.Add("Links","Work for *** HomePage Quick Links web part.",$listTemplate)

$ListCollection.Update()

$LinksList = $HomePageWeb.Lists|where{$_.title -like 'Links'}

Write-Host "Add the quick launch for Links list..."

$LinksList.OnQuickLaunch = "True"

#Create column fields to the list

Write-Host "Create the fields..."

$TextFieldType = [Microsoft.SharePoint.SPFieldType]::Text

$NumberFieldType = [Microsoft.SharePoint.SPFieldType]::Number

$ChoiceFieldType = [Microsoft.SharePoint.SPFieldType]::Choice

#Add choices under the choice field

$choices = New-Object System.Collections.Specialized.StringCollection

$choices.Add("_blank")

$choices.Add("_self")

#Add the fields to the Links List

Write-Host "Add the fields to the Links list..."

$DescriptionField = $LinksList.Fields.Add("Description",$TextFieldType,$false)

$OrderField = $LinksList.Fields.Add("Order",$NumberFieldType,$false)

$RedirectURLField = $LinksList.Fields.Add("RedirectURL",$TextFieldType,$false)

$RedirectMethodField = $LinksList.Fields.Add("RedirectMethod",$ChoiceFieldType,$false,$false,$choices)

#Add the fields to the Links List's default view

Write-Host "Add the fields to the All Items view..."

$LinksDefaultView = $LinksList.views|where{$_.views -like 'All Items'}

$LinksDefaultView.ViewFields.Add($DescriptionField)

$LinksDefaultView.ViewFields.Add($OrderField)

$LinksDefaultView.ViewFields.Add($RedirectURLField)

$LinksDefaultView.ViewFields.Add($RedirectMethodField)

$LinksDefaultView.Update()

#Add the "Try to find a site?" item to the Links list

Write-Host "Add the 'Try to find a site?' item to the Links list..."

$DefaultListItem = $LinksList.AddItem()

$DefaultListItem["Title"] = "Try to find a site?"

$DefaultListItem["Description"] = "FNA(Financial News Alert)"

$DefaultListItem["Order"] = 1

$DefaultListItem["RedirectURL"] = "https://***damanager.migration.net:15999/SiteCollectionDirectoryReport/ViewPublishReports?SPHostUrl=https://teamsite.migration.net/sites/ForHomePageTesting/"

$DefaultListItem["RedirectMethod"] = "_self"

$DefaultListItem.Update()

$LinksList.Update()

#Modify the configuration information of the Quick Links web part.

Write-Host "Begin to configure the Quick Links web part..."

$QuickLinksWebPart = $limitedWebPartManager.WebParts|where{$_.DisplayTitle -like '*Quick Links*'}

$QuickLinksWebPart.ChromeType = "TitleOnly"

#Modify the configuration information of the Administration web part.

Write-Host "Begin to configure the Administration web part..."

$AdministrationWebPart = $limitedWebPartManager.WebParts|where{$_.DisplayTitle -like '*Administration*'}

$AdministrationWebPart.ChromeType = "None"

$AdministrationWebPart.DesktopActivityLogURL = "https://teamsite.migration.net/sites/activitylog test"

$AdministrationWebPart.TaxonomyManagementURL = "https://teamsite.migration.net/sites/Taxonomy%20Case/_layouts/15/***TaxonomyManagement/TaxonomyManagement.aspx"

$AdministrationWebPart.CollaborationDashboardURL = "https://teamsite.migration.net/sites/ForHomePageTesting/SitePages/collabration.aspx"

$AdministrationWebPart.ServiceCatalogueAdministrationURL = "https://***damanager.migration.net:15999"

$AdministrationWebPart.DocAveURL = "https://***damanager.migration.net:14999"

#$AdministrationWebPart.WorkflowWSUrl

#$AdministrationWebPart.WorkflowWSMethod

#$AdministrationWebPart.WorkflowJUMPUrl

#Save the changes to the web parts

Write-Host "Begin to save all the configurations..."

$limitedWebPartManager.SaveChanges($MyDocumentsWebPart)

$limitedWebPartManager.SaveChanges($SiteManagementWebPart)

$limitedWebPartManager.SaveChanges($MyTasksWebPart)

$limitedWebPartManager.SaveChanges($QuickLinksWebPart)

$limitedWebPartManager.SaveChanges($AdministrationWebPart)

$HomePage.Update()

$HomePage.CheckIn("")

$HomePage.ListItem.File.Publish("")

$HomePageWeb.Dispose()

Write-Host "The HomePage has been configured successfully!"

Read-Host "Press any key to continue"
相關文章
相關標籤/搜索