Add-PSSnapin Microsoft.SharePoint.PowerShell # Site URL where the chart will be provisioned $targetWebUrl = 'http://dev7.dev.local/subsite1' # Pages library $pagesLibrary = 'Site Pages' # Page name $targetPage = 'Page1.aspx' # Zone to add chart to $webPartZone = "Header" # Index of the added webpart $webPartIndex = 0 # Site URL of the data source list $dataSourceWebUrl = 'http://dev7.dev.local/DD' # Data source list name $dataSourceListName = 'Data' # Path to the config file: $pathToChartConfig = "C:\DDExport\chart_export.txt" Try { $web = Get-SPWeb $targetWebUrl $list = $web.Lists[$pagesLibrary]; $rootFolder = $list.RootFolder; $pageUrl = $rootFolder.ServerRelativeUrl + '/' + $targetPage; #check if page exists, add if not if ($web.GetFile($pageUrl).Exists){ Write-Host "$pageUrl already exists" -ForegroundColor Yellow ; } else{ $rootFolder.Files.Add($pageUrl, [Microsoft.SharePoint.SPTemplateFileType]::StandardPage); Write-Host "$pageUrl is added successfully" -ForegroundColor Green ; } $dsWeb = Get-SPWeb $dataSourceWebUrl $dsList = $dsWeb.Lists[$dataSourceListName] [string]$config = Get-Content -Path $pathToChartConfig # Only use these lines to programmatically relative path in the config file, if not done manually $config = $config -replace '{webUrl}', $dsWeb.ServerRelativeUrl $config = $config -replace '{listUrl}', $dsList.RootFolder.Url # adding chart web part $webPartManager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) $webPart = New-Object Microsoft.SharePoint.WebPartPages.ContentEditorWebPart; $webPart.PartStorage = $config; $webPart.ContentLink = $web.Site.ServerRelativeUrl.TrimEnd('/') + '/style library/plumsail/dashboard/chart.html'; $webpartmanager.AddWebPart($webpart, $webpartzone, $index); Write-Host 'Chart is added successfully' -ForegroundColor Green; } Catch { Write-Error $_.Exception.Message }