Add Script Editor Web Part :
I had coding a function about adding scripteditorwebpart to page, here is the examplt to call function:
AddScriptEditorWebPart "http://localhost" "/SitePages/Home.aspx" "JSFile.js"
function AddScriptEditorWebPart($siteUrl, $pageUrl, $jsLink){
$webPartProperty_Visible = $true
$web = get-spweb $siteUrl
$defaultPage = $web.GetFile($pageUrl)
# Get the LimitedWebPartManager
$webpartmanager=$defaultPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#Create fancy GUID
$lvwpGuid1 = [System.Guid]::NewGuid().ToString()
$lvwpKey = "g_" + $lvwpGuid1.Replace("-","_")
# Instantiate wp
$lvwp =New-Object Microsoft.SharePoint.WebPartPages.ScriptEditorWebPart
$lvwp.ID = $lvwpKey
$code = "$"
$lvwp.Content = @"
<script src="http://code.jquery.com/jquery-2.0.3.min.js" ></script>
<script type="text/javascript" src="$jsLink"></script>
"@
$lvwp.Title = "DocumentReadyForNewOrUpdatePost"
$lvwp.Visible = $webPartProperty_Visible
$lvwp.ChromeType = "None"
$lvwp.HorizontalAlign = "Center"
# Add the web part
$webpartmanager.AddWebPart($lvwp, "Main", 0);
# Update the web
$web.Update();
write-host "success"
$web.Dispose()
write-host "Done"
}
Add Content Editor Web Part :
AddScriptEditorWebPart "http://localhost" "/SitePages/Home.aspx" "file.txt"
function AddContentEditorWebPart($siteUrl, $pageUrl, $conetntLink){
$webPartProperty_Visible = $true
$web = get-spweb $siteUrl
$defaultPage = $web.GetFile($pageUrl)
# Get the LimitedWebPartManager
$webpartmanager=$defaultPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#Create fancy GUID
$lvwpGuid1 = [System.Guid]::NewGuid().ToString()
$lvwpKey = "g_" + $lvwpGuid1.Replace("-","_")
# Instantiate wp
$lvwp =New-Object Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
$lvwp.ID = $lvwpKey
$code = "$"
$lvwp.ContentLink = @"
$conetntLink
"@
$lvwp.Title = "DocumentReadyForNewOrUpdatePost"
$lvwp.Visible = $webPartProperty_Visible
$lvwp.ChromeType = "None"
$lvwp.HorizontalAlign = "Center"
# Add the web part
$webpartmanager.AddWebPart($lvwp, "Main", 0);
$web.Update();
$web.Dispose()
}