Add custom webpart to a page using power shell
if((Get-PSSnapin « Microsoft.SharePoint.PowerShell » ) -eq $null) { Add-PSSnapin « Microsoft.SharePoint.PowerShell »}; [System.Reflection.Assembly]::LoadWithPartialName(« Microsoft.SharePoint ») [System.Reflection.Assembly]::LoadWithPartialName(« Microsoft.Publishing ») [System.Reflection.Assembly]::LoadWithPartialName(« System ») $site = new-object Microsoft.SharePoint.SPSite(« http://mysite »); $web = $site.OpenWeb() $fileDWP = $saveFolder + « myCustom.dwp » $errorMsg = « » [Microsoft.SharePoint.SPList]$wpList $site.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::WebPartCatalog) $fileStream = ([System.IO.FileInfo](Get-Item $fileDWP)).OpenRead() [Microsoft.SharePoint.SPFolder]$wpFolder = $wpList.RootFolder [Microsoft.SharePoint.SPFile]$wpFile = $wpFolder.Files.Add(« myCustom.webpart », $fileStream, $true) $wpFile.Update(); [System.Xml.XmlReader]$xmlReader = [System.Xml.XmlReader]::Create($wpFile.OpenBinaryStream()) [Microsoft.SharePoint.Publishing.PublishingWeb]$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web); [Microsoft.SharePoint.SPFile]$defaultPage = $pubWeb.DefaultPage; …