Monthly Archives: November 2011

SharePoint 2010 – Timer Job you should know about

So you fire up your new SharePoint 2010 server, build out your site(s) and give users access. Then about a month later some users get an email from your SharePoint Server. You think to yourself… “I didn’t set anything up to send emails.” You grab a copy of the email and you see SharePoint is sending out colleague and keyword suggestions to some of your users. Yeah, this timer job is turned on by default. I like the idea behind this type of data being sent out, but only for certain environments and when I ask it to. I would never use this in a DEV or QA server. As you can guess, one of the first steps when I fire up a new server now is to disable the job below…

User Profile Service – My Site Suggestions Email Job


Powershell to find out web parts are on your pages

Here’s a script to get a list of what web parts are on each page in a site collection. Helps when you need to find all the pages you need to update with a new version of a web part…

cls

# Add SharePoint cmdlets reference

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

function enumerateWebParts($Url) {

    $site = new-object Microsoft.SharePoint.SPSite $Url

    foreach($web in $site.AllWebs) {

        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {

            $pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)

            $pages = $pWeb.PagesList

 

            Write-Host “Processing Web:” $pWeb.Url “…” -ForegroundColor Magenta

 

            foreach ($item in $pages.Items) {

                $fileUrl = $webUrl + “/” + $item.File.Url

                Write-Host ”   ” $fileUrl -ForegroundColor Green

                $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);

                $wps = $manager.webparts

                $wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”}, DisplayTitle, IsVisible, @{Expression={$_.GetType().ToString()};Label=”Type”}

            }

        }

        else {

            Write-Host ”   Not a publishing web:” $web.Url”. Looking for Site Pages library.” -ForegroundColor Magenta

            $pages = $null

            $pages = $web.Lists[“Site Pages”]

 

            if ($pages) {

                Write-Host ”   ” $pages.Title “found.” -ForegroundColor Green

 

                foreach ($item in $pages.Items) {

                    $fileUrl = $webUrl + “/” + $item.File.Url

                    $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);

                    $wps = $manager.webparts

                    $wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”}, DisplayTitle, IsVisible, @{Expression={$_.GetType().ToString()};Label=”Type”}

                }

            }

            else {

                Write-Host ”    Site Pages library not found.” -ForegroundColor Red

            }

        }

 

        Write-Host “… completed processing” $web “…” -ForegroundColor Magenta

    }

}

 

$row = enumerateWebParts(‘http://yoursitecollection’)

$row | Out-GridView


Find all checked out files in the farm

Here’s a better script I found to get all checked out files on the farm. You can just add the check-in code from my previous blog if needed.

function Get-CheckedOutFiles() {

    foreach ($web in (Get-SPSite -Limit All | Get-SPWeb -Limit All)) {

        Write-Host “Processing Web: $($web.Url)…”

        foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {

            Write-Host “`tProcessing List: $($list.RootFolder.ServerRelativeUrl)…”

            foreach ($item in $list.CheckedOutFiles) {

                if (!$item.Url.EndsWith(“.aspx”)) { continue }

                $hash = @{

                    “URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);

                    “CheckedOutBy”=$item.CheckedOutBy;

                    “CheckedOutByEmail”=$item.CheckedOutByEmail

                }

                New-Object PSObject -Property $hash

            }

            foreach ($item in $list.Items) {

                if ($item.File.CheckOutStatus -ne “None”) {

                    if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) { continue }

                    $hash = @{

                        “URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);

                        “CheckedOutBy”=$item.File.CheckedOutByUser;

                        “CheckedOutByEmail”=$item.File.CheckedOutByUser.Email

                    }

                    New-Object PSObject -Property $hash

                }

            }

        }

        $web.Dispose()

    }

}

Get-CheckedOutFiles | Out-GridView

From here –> http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/


Check in documents with Powershell SharePoint 2010

This will help out when you need to force files to be checked in. It can also be modified to find all the checked out files and notify users…

function CheckInDocument([string]$url)

{

$spWeb = Get-SPWeb $url

$getFolder = $spWeb.GetFolder(“Shared Documents”)

$getFolder.Files | Where { $_.CheckOutStatus -ne “None” } |

ForEach

    {

          Write-Host “$($_.Name) is Checked out To:

          $($_.CheckedOutBy)”

          $_.CheckIn(“Checked In By Administrator”)

          Write-Host “$($_.Name) Checked In” -ForeGroundColor Green

     }

     $spWeb.Dispose()

}

Here’s an example on running the function:

CheckInDocument http://SP

Found here


Pretty much the only way you should deploy a custom master page

http://sharepointchick.com/archive/2010/03/26/deploying-a-custom-master-page-in-sharepoint-2010.aspx


Powershell through all your sites

This script specifically gets site collection admins, but it can be modified to get other data you might be interested in…

$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
foreach($site in $spWebApp.Sites)
{
    foreach($siteAdmin in $site.RootWeb.SiteAdministrators)
    {
        Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
    }
    $site.Dispose()
}
$rootSite.Dispose()
found it here.. http://geekswithblogs.net/bjackett/archive/2011/03/25/powershell-script-to-display-all-sharepoint-site-collection-administrators-in.aspx