Tuesday, September 4, 2012

PowerShell To Change Set Default Page

PowerShell Script To Set a New Default Page:

$site = Get-SPSite http://server/sites/sitename
$web = $site.RootWeb
$folder = $web.RootFolder
$folder.WelcomePage = "Shared%20DocumentLibrary/CustomPage.aspx")
$folder.update()
$web.Dispose()
$site.Dispose()
 
Thanks 

Enable “Audit Log Reports” in Site Settings Page

Hello Friends,

Many times we need to generate Audit Reports in SharePoint Sites. To enable this link in Site Settings we need to activate "Reporting" Site Collection Level Feature.

PowerShell Script To Enable  “Audit Log Reports”:

Enable-SPFeature –identity "Reporting" -URL $url -ErrorAction SilentlyContinue

This way we can create number of scripts including Custom one.

Happy Reading!!!

Monday, September 3, 2012

PowerShell To create Retention Policies for Content Types

Hi Friends,

PowerShell is really a very powerful tool. Its not just a command prompt, we can also do coding into this.
Here I am using Powershell to create Policies on Content Types. I am creating Retention Policies and Auding Policy on Content Types. I am using One file "D:\Test\ContentTypes.txt" which contains data(content types) description according which we are applying Policies on those.

Data in the "D:\Test\ContentTypes.txt" will be in following format:

Name,Property,Period,PeriodType
One CTypeName,Created,15,Years
Two CTypeName,Created,25,Years
Three CTypeName,Created,Permanent,Years

function  abc()
{
$url = "http://server:1717/sites/TestTopLevelSite/"

$site = get-spsite $url
$web = $site.openweb()

Enable-SPFeature –identity "LocationBasedPolicy" -URL $url -ErrorAction SilentlyContinue

$CTList = Import-Csv D:\Test\ContentTypes.txt

echo "Processing Content Types"

ForEach ($item in $CTList){

$Name = $($item.Name)
$Property = $($item.Property)
$Period = $($item.Period)
$PeriodType = $($item.PeriodType)

$contentType = $web.ContentTypes[$Name]

if (($Period -ne "IND") -or ($Period -notcontains "MAX")) {

if($contentType){

[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::CreatePolicy($contentType, $null);

$newPolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($contentType);

$newPolicy.Items.Add("Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration",
 "<Schedules nextStageId='3'>"+
 "<Schedule type='Default'>"+
 "<stages>"+
 "<data stageId='1' stageDeleted='true'></data>"+
 "<data stageId='2'>"+
 "<formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'>"+
 "<number>"+$Period+"</number>"+"<property>"+$Property+"</property>"+
 "<period>"+$PeriodType+"</period>"+
 "</formula>"+
 "<action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.MoveToRecycleBin' />"+
 "</data>"+
 "</stages>"+
 "</Schedule>"+
 "</Schedules>");

$newPolicy.Items.Add("Microsoft.Office.RecordsManagement.PolicyFeatures.PolicyAudit",
 "<Audit>"+
 "<Update />"+
 "<View />"+
 "<CheckInOut />"+
 "<MoveCopy />"+
 "<DeleteRestore />"+
 "</Audit>");

$newPolicy.Update();

}
}
}

$web.Dispose()
$site.Dispose()

echo "Finished!!!"

}

Happy Reading!!!

SharePoint 2010 Solution Deployment Gets Hanged

Hi Friends,

During a SharePoint 2010 Solution Deployment its gets hanged and its hanged in "solution-deployment-solutionName.wsp-0".

To resolve this issue we should try the below steps:
1. Stop SPAdminV4
2. Start-SPAdminJob
3. Start SPAdminV4

Example :

$spAdminServiceName = "SPAdminV4"
Stop-Service -Name $spAdminServiceName
Start-SPAdminJob -Verbose
Start-Service -Name $spAdminServiceName

Thanks
Prabhat