Query SharePoint ULS log using PowerShell

Get-SPLogEvent -StartTime “21/01/2012 00:38” -EndTime “21/01/2012 09:09” | Where-Object {$_.Message -like “Message contains something*”} | select Timestamp, Correlation  | Format-Table -Wrap –  > L:\Backup\ErrorFile.csv -Verbose


PowerShell to update SharePoint 2010 list item

$spWeb = Get-SPWeb -Identity “http://yousite/sites/test/test2
$spList = $spWeb.Lists[“List Name Goes Here”]
$spListItem = $spList.GetItemById(4)
$spListItem[“SomeColumnName”] = “Some Value”

Change the ID number in GetItemById

PowerShell to get SharePoint 2010 field name from site collection

 [Parameter(Mandatory=$true, HelpMessage=’-Url http://sharepointurl/site/test – Please provide the Url of the Site.’)]
 [Parameter(Mandatory=$true, HelpMessage=’-FieldName – Please provide the Internal Field Name to remove.’)]
 [Parameter(Mandatory=$true, HelpMessage=’-FieldType – Please provide the Field Type to remove.’)]

$site = Get-SPSite -Identity $Url -ErrorAction SilentlyContinue;
if($site -ne $null)
 Write-Host “Checking Site Collection:” $Url “Field:” $FieldName “….”-NoNewline;
 $checkSiteColumn = $site.RootWeb.Fields | ?{($_.InternalName -eq $FieldName) -and ($_.TypeAsString -eq $FieldType)};
 if($checkSiteColumn -eq $null)
  Write-Host “Field Not Found!” -ForegroundColor Yellow;
  Write-Host “Field Found” -ForegroundColor Green;
 foreach($checkWeb in $site.AllWebs)
  $caseFileList = $checkWeb.Lists.TryGetList(“Case Files”);
  if($caseFileList -ne $null)
   Write-Host “Checking CaseFiles DocLib in” $checkWeb.ServerRelativeUrl “…”-NoNewline;
   $checkField = $caseFileList.Fields | ?{($_.InternalName -eq $FieldName) -and ($_.TypeAsString -eq $FieldType)};
   if($checkField -eq $null)
    Write-Host “Not Found!” -ForegroundColor Yellow;
    Write-Host “Found!” -ForegroundColor Green;
 Write-Host “Site: ” $Url ” Not Found” -ForegroundColor Yellow;

How to enable delete button to delete SharePoint 2010 Content Type column

Here is the PowerShell script to bring back the Content Type delete button:

$site = Get-SPSite-Identity http://sharepointsite/sites/test 

$ctype =$site.RootWeb.Fields | ?{$_.InternalName -eq“InternalFieldName”}



Run the above script from the server and check that the content type button now appears.

Powershell to get count of your SharePoint sites

Often you may have the need to find the need to take a count of all your sites by site collection in your web application. Here is a small #powershell script which will do the work for you, just change the name of your web application:

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

$webapp=Get-SPWebApplication http://yourwebapplication;
$webapp.Sites | %{Write-Host $_.Url ” -Count: ” $_.AllWebs.Count};

Hit like if this was helpful…