Wednesday, July 1, 2015

Sharepoint Powershell - Enable logging - Verbose

To view the current Log Level in Sharepoint


To create a new log file

New- SPLogFile

To set the ULS logging to Verbose

Set-SpLogLevel -TraceSeverity Verbose

To set the ULS logging to VerboseEx - Verbose Extended Logs- This will captured SQL queries in the log.

Set-SpLogLevel -TraceSeverity VerboseEx 

To set Eventlog along with trace log(ULS)

Set-SpLogLevel -TraceSeverity Verbose  -EventSeverity Verbose

To Clear the Log Level


To collect logs from all the servers based on Correlation

Merge-SPLogFile -Path "C:\Logs\Log.log" -correlation <correlation id>

To collect logs from all the servers based on date & time

Merge-SPLogFile -Path "C:\Logs\Log.log" -Overwrite -StartTime "mm/dd/yyyy hh:mm" -EndTime "mm/dd/yyyy hh:mm"

Sharepoint Powershell - Add bulk items to Sharepoint lists


$webURL = "http://SiteURL"
$listName = "List_Name"

$web = Get-SPWeb $webURL
$list = $web.Lists[$listName]

#Add 1000 items to the list

for ($i=1;$i -lt 1001; $i++) {
$newItem = $list.Items.Add()

           #Add properties to this list item

           $newItem["Title"] = "Test Item"+ $i.ToString()


Sharepoint Powershell - To set master page

To find out which master page is currently applied

$web = Get-SPWeb http://siteurl

To set a custom master page to the site

$web = Get-SPWeb http://siteurl
$web.CustomMasterUrl = "/_catalogs/masterpage/custom.master"
$web.MasterUrl = "/_catalogs/masterpage/custom.master"