maandag 28 januari 2013

Get all recycle bins filled with content.







To know in which sitecollection the recycle bin is filled.

Function GetallFilledRecyclebins($LogFile, $SiteUrl)

{
     Start-Transcript -Path $LogFile


     $sitecollection = SPSite($SiteUrl)

     foreach ($web in $sitecollection.AllWebs)

     {
        
Write-Host $web.Url + "->" +  $web.RecycleBin.Count

     }

     Stop-Transcript

}

GetallFilledRecyclebins c:\temp\log.log http://www.url.com

Get all version enabled lists







To search on all site collections manually to version enabled lists takes a lot of time.

So because of that i wrote a ps script.

Function GetAllVersionEnabledLists($LogFile, $SiteUrl)
{

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

Start-Transcript -Path $LogFile

$sitecollection = SPSite($SiteUrl)
foreach ($web in $sitecollection.AllWebs)
{
foreach($list in $web.lists)
{
if ($list.EnableVersioning -eq $true)
{
Write-Host ($site.Url +"-" +  $web.Title +"-"+ $list.Title + "->" + $list.EnableVersioning)
}
}
}

Stop-Transcript
}


Example : GetAllVersionEnabledLists c:\temp\log.log http://url 

dinsdag 22 januari 2013

Read ULS log with powrshell


When solving issues on a SharePoint environment. You need a lot of times take a look at the ULS logs of SharePoint. Instead of logging in on a remote desktop connection (RDC) you can create a file share of the log files folder of SharePoint.

With the next PowerShell script you can read the uls logs via the file share based on your Correlation ID.



Function Get-ULSLog ($correlationid, $timelimit = 30) {
                @("Server 1","Server 2","Server 3") |
                % {gci "\\$_\Name of the file share\*.log"} |
                ? { $_.LastWriteTime -gt (Get-Date).AddMinutes(-$timelimit)} | 
                import-csv -delim "`t" | ? {$_.Correlation -match $correlationid}
}


Get-ULSLog "Correlation ID" 30



Have fun, it will save a lot of time.