SP 2013 Publish Master page gallery using Powershell script

The below script will be useful for approving the master page gallery files using Powershell script


Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue
$strStatusApproved= [Microsoft.SharePoint.SPModerationStatusType]::Approved;
$strStatusRejected= [Microsoft.SharePoint.SPModerationStatusType]::Rejected;
$strStatusPending= [Microsoft.SharePoint.SPModerationStatusType]::Pending;
$webAppUrl = "http://SPSiteURL"
function fnCheckInFolder($folder)
{
if($folder-ne $null -and $folder.item -ne $null -and $folder.item.ModerationInformation -ne $strStatusApproved -and $folder.item.ModerationInformation -ne $strStatusRejected )
{
write-host (" Approving the folder {0} " -f $folder.item.Url)
$comment = $folder.item.ModerationInformation
$comment.Status = $strStatusApproved
$folder.Item.Update()
$folder.update()
}
$j=0
if($folder-ne $null -and $folder.Url.Contains("/img") -eq $true)
{

$folder.Files |?{ $_.Item -ne $null -and $_.Item.File.CheckOutType -ne “None”} | % {
$_.Item[“ContentTypeId”]=”0x010100C5033D6CFB8447359FB795C8A73A2B19″
$_.Item.Update()
$_.Item.File.CheckIn(“”)
$_.Item.file.Publish(“”)
$_.Item.file.Approve(“”)

}
}
$folder.Files | ?{ $_.Item -ne $null -and $_.Item.Properties[“HtmlDesignLockedFile”] -eq $null -and $_.MinorVersion -ne 0 } | %{
if($_.Url.Contains(“.html”) ){
# design file .html master page checkin
$_.Item[“ContentTypeId”]=”0x0101000F1C8B9E0EB4BE489F09807B2C53288F0054AD6EF48B9F7B45A142F8173F171BD10003D357F861E29844953D5CAA1D4D8A3A”
$_.Item.Update()
$_.Item.File.CheckIn(“”)
$_.Item.file.Publish(“”)
$_.Item.file.Approve(“”)
Write-Host (” Master page {0} status ” -f $_.Url,$_.item.File.CheckOutStatus);

}

if($_.Url.Contains(“.css”) -or $_.Url.Contains(“.js”)) {

$i =0
if ($_.Item.File.CheckOutType -ne “None”)
{
# design files css/js checkin
Write-Host (” Items Publishing {0} ” -f $_.Url,$_.Item.ContentType.Name );
$_.Item[“ContentTypeId”]=”0x010100C5033D6CFB8447359FB795C8A73A2B19″
$_.Item.Update()
$_.Item.File.CheckIn(“”)
$_.Item.file.Publish(“”)
$_.Item.file.Approve(“”)
}

}

}

$folder.SubFolders | %{ fnCheckInFolder $_;}
}

$rootWeb = Get-SPWeb $webAppUrl
$rootWeb.Title
$masterPageFolder= $rootWeb.GetFolder(“_catalogs/masterpage”)
fnCheckInFolder($masterPageFolder)

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s