Thursday, 16 October 2014

How to list and remove orphaned users in SharePoint 2013 using powershell

First run the following script to get a list of the users and what their access is:
$urlWeb = "WebUrl"
Get-SPUser -Web $urlWeb | select UserLogin, @{name=”Exlicit given roles”;expression={$_.Roles}}, @{name=”Roles given via groups”;expression={$_.Groups | %{$_.Roles}}},Groups | format-Table -auto

Then Run the following to remove individual user permissions. This is handy if you have migrated from a test environment using FBA and the existing accounts dont exists in your production FBA user store. NOTE: you substitute the following ProviderNames based on the claims auth type you are using. i:0#.f|FBAProviderName | i:0#.w|windowsProviderName | WindowsDomain\UserName
PS E:\> Remove-SPUser -identity "i:0#.f|ProviderName|vand" -web WebUrl

Monday, 6 October 2014

Easy way to move pages from a SharePoint 2010 site to a SharePoint 2013 where the page layout does not exist.

This is a handy way to move pages from one site to a completely different site in SharePoint. Note, that I was able to move pages from a 2010 site into a 2013 site where the page layout used did not exist on the 2013 site. This involves running a powershell script to update the page layouts to the body only 2013 layout.

1st open the 2010 pages library in explorer mode and copy the folder containing the page you want to move. Then paste them into the 2013 pages library. At this stage the pages may break as they reference a page layout that does not exist in the 2013 site.

Now run the following script to update the page layouts to the body only 2013 layout:
$spWeb = Get-SPWeb("http://siteURL")

$list = $spWeb.Lists["Pages"]

foreach ($folderItem in $list.Folders)
{
 if($folderItem.Name -eq "FolderName")
 {
    Write-Host "Folder: " $folderItem.Name "Count: " $folderItem.Folder.ItemCount
  foreach($file in $folderItem.Folder.Files)
  {
   Write-Host "File name is " $file.Name
   $file.CheckOut("Online",$null)
   $file.Properties["PublishingPageLayout"] = "/_catalogs/masterpage/PageFromDocLayout.aspx, Body only"
   $file.Update()
   $file.CheckIn("Update page layout via PowerShell",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
   Write-Host "Layout updated"
  }
 }
}