Quantcast
Channel: SharePoint Diary
Viewing all 1058 articles
Browse latest View live

Find All Checked Out Files and Check-In them Back

$
0
0
I'm Sharing one of the PowerShell script I used in MOSS 2007 to SharePoint 2010 migration. Since its very difficult to check-in back all the checked-out files after migration, its a best practice to check-in all checked out files prior.

This PowerShell script will Scans, Generates Report and check-in all checked out files. Run this script with Farm Administrator privileges.

 
# For MOSS 2007 compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets

Function Get-SPWebApplication()
{   
  Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
  return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}

Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )

   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}
 
Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion

 Function GetCheckedOutFiles()
 {  
    #Define 'Web Application URL' as Mandatory Parameter
    Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
 
 #Get the Web Application
    $WebApp=Get-SPWebApplication($WebAppURL)

    #Write the CSV Header - Tab Separated
 "Site Collection Name `t Site Name`t Library `t File Name `t File URL `t  Last Modified `t Checked-Out By" | out-file CheckedOutFiles.txt

 #Arry to Skip System Lists and Libraries
 $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates",  
                 "List Template Gallery", "Theme Gallery", "Reporting Templates",  "Solution Gallery",
           "Style Library", "Web Part Gallery","Site Assets", "wfpub")
 
   #Loop through each site collection
  foreach($Site in $WebApp.Sites)
   {
    #Loop through each site in the site collection
     foreach($Web in $Site.AllWebs)
   {
            #Loop through each document library
            foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))
            {
                #Get only Document Libraries & Exclude Hidden System libraries
                if ( ($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )
                {
     #Loop through eadh Item
      foreach ($ListItem in $List.Items) 
      {
                  if( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))
      {
                        #Log the data to a CSV file where versioning size > 0MB!
                        "$($Site.RootWeb.Title) `t $($Web.Title) `t $($List.Title) `t $($ListItem.Name) `t $($Web.Url)/$($ListItem.Url) `t  $($ListItem['Modified'].ToString()) `t  $($ListItem.File.CheckedOutByUser)" | Out-File CheckedOutFiles.txt -Append
       #*** Uncomment the below line to Check-in****#
       $ListItem.File.Checkin("Checked in by Administrator")
      }
                    }
                }
            }
   $Web.Dispose()          
        }
 $Site.Dispose()          
    }
    #Send message to output console
    write-host "Checked out Files Report Generated Successfully!"
}

#Call the Function to Get Checked-Out Files
GetCheckedOutFiles "http://sharepoint.company.com"

Bulk Check-In all checked-out files in Site collection:
If you want to check-in all checked-out files by you, use "Content and Structure" link under site settings. You have the option "Checked Out to Me" which lists all files checked-out to you. Just select the desired files and click Check-in from actions menu.

Get All Files of Particular Type

$
0
0
In a Branding revamp project, After updating new logo on the SharePoint CSS Files, Found there are lot of InfoPath forms out there with old logo. So had to figure out all deployed InfoPath XSN Templates!

PowerShell Script to Find all XSN Files:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
#For SharePoint 2007
function global:Get-SPSite($url){
    return new-Object Microsoft.SharePoint.SPSite($url)
}

#Function to Scan XSN Files
Function GetXSNFiles($Folder)
{
    foreach ($File in $Folder.Files | Where-Object {$_.Name -match ".xsn"} )
    {
     #Write data to CSV File
     "$($Folder.ParentWeb.Site.RootWeb.Title)" +"`t"+ "$($Folder.ParentWeb.Title)" +"`t" + "$($Folder.ParentWeb.URL+"/")$($File.URL)" +"`t" + "$($File.TimeLastModified)" >> XSNTemplates.csv
    }

    #Iterate through all subfolders
    foreach ($SubFolder in $Folder.SubFolders)
    {
        #Call the function recursively
        GetXSNFiles $SubFolder
    }
}
 
#Write the CSV header
"Site Collection `t Site `t Form Template `t Last Modified" > XSNTemplates.csv

#Get the web application
#Write-Host "Enter the Web Application URL:"
$WebAppURL= "http://sharepoint.crescent.com"   #$WebAppURL= Read-Host
$SiteColletion = Get-SPSite($WebAppURL)
$WebApp = $SiteColletion.WebApplication
 
#Loop through all site collections of the web app
    foreach ($site in $WebApp.Sites)
    { 
       #Get the collection of webs
       foreach($web in $site.AllWebs)
        {
              write-host "scanning site" $web.title "@" $web.URL
              
              #Call the function to Get XSN Files
              GetXSNFiles($Web.RootFolder)
              
         #Dispose web object
         $web.dispose()
        }
 
        #Dispose site object
        $site.Dispose()
    }
Write-host  "Report Generated: XSNTemplates.csv" -foregroundcolor green

Script will search each and every list and library for specific file type and log that information to a Tab Separated text file.

Search SharePoint Recycle bin with SPRecycleBinQuery

$
0
0
Searching inside SharePoint recycle bin for a deleted item or file, is a pain especially when you have LOT of deleted items and files in SharePoint recycle bin. Unfortunately SharePoint doesn't provide Search capability in recycle bin and you have to press Next>> <<Prev buttons to search for your file. 

We can perform Search on SharePoint Recycle bin items with SPRecycleBinQuery. Here is an example of SPRecycleBinQuery with PowerShell.

Good news is: If you know your file name, can search inside recycle in programmatically with PowerShell!

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Get the Site collection
$site = new-object Microsoft.SharePoint.SPSite("http://sharepoint.company.com")

#Create new object for SPRecycleBinQuery
$query = new-object Microsoft.SharePoint.SPRecycleBinQuery

#$query.ItemState = "FirstStageRecycleBin"
$query.ItemState = "SecondStageRecycleBin"

#How many Rows to be returned
$query.RowLimit = 100

#Call GetRecycleBinItems to Search Inside SharePoint Recycle Bin
$DeletedItemsColl = $site.GetRecycleBinItems($query)

#Filter Result
$Result= $DeletedItemsColl | where  {$_.Title -match ".txt"}

#Write output
$Result | foreach-object {
    (Write-Host "Found Item:" $_.Title)
    (write-host "Created by:" $_.AuthorName)
    (write-host "Deleted by:" $_.DeletedByName)
    (write-host  "Deleted Date:"$_.DeletedDate)
  (write-host  "File Size(Bytes):" $_.Size)
  (write-host  "Original Location:" $_.DirName)
  (write-host "Web:" $_.web.URL)
 (Write-Host "------------------------------------")
  }
 
We can search recycle bin items based on File Name, Deleted By, Deleted Time, Size, etc. Its also possible to either restore or permanently delete the files by calling approximate method.This is extremely useful if you want to search recycle bin programmatically!

Nintex Workflow Tasks Item not found Error

$
0
0
Problem: Nintex Workflow tasks displays : * Item Not found error!
Nintex Workflow Tasks Item not found Error

Cause: Workflows are initiated and items in which workflows ran, are deleted by end-user. When I tried terminating the workflows, it gave "Server was unable to process the request --> Values does not fall within the expected range." error message! When I tried opening workflow task, got "Value does not fall within the expected range" Error!!

Solution: Use NWAdmin tool to terminate the tasks for deleted items. Here is how:
Go to command prompt,

CD "C:\Program Files (x86)\Nintex\Nintex Workflow 2007"

NWAdmin -o SyncTerminatedWorkflows -url https://sharepoint.company.com/finance/v3 -terminatedeleteditems
nintex terminate deleted item's workflow tasks

So, to avoid such issues, always terminate the workflow and then delete the items. Item not found may also occur when user doesn't has at least read access on the item!

Create Update Copy Delete SharePoint Views with PowerShell

$
0
0
Requirement is: There are lot of document libraries in a SharePoint site. Periodically, in all libraries there is a need to:
  • Create a new view
  • Update an existing view with new filter condition
  • Create new new by copying existing view and modify the filter
  • Delete an existing view
Team wanted to automate the process of creation of new SharePoint list views, Deleting existing views, Update filters on existing views and copy existing views. Wrote PowerShell code to do the above:

Create SharePoint List View in PowerShell:
#Function to create new View
Function CreateNewView()
 {  
  Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$ListName, [Parameter(Mandatory=$true)] [string]$ViewName ) 
  $site = Get-SPSite $SiteURL
  $web = $site.openweb()
  #Get the List
  $list=$web.lists[$ListName]
   #View Fields 
   $viewFields = New-Object System.Collections.Specialized.StringCollection
   #Add fields to the view
   $viewFields.Add("Global Entity") > $null
   $viewFields.Add("Document Type")> $null
   $viewFields.Add("Risk")> $null
   $viewFields.Add("Year")> $null

    #Set View options
    $viewRowLimit="100"
    $viewPaged=$true
    $viewDefaultView=$false
    $viewQuery="<Where><Eq><FieldRef Name='Document_x0020_Type' /><Value Type='Choice'>Customer Reconciliation</Value></Eq></Where>"

    #Crete new view
    $newview = $list.Views.Add($ViewName, $viewFields, $viewQuery, $viewRowLimit, $viewPaged, $viewDefaultView)

   #Send message to output console
   write-host "New View $($ViewName) Created Successfully!" -foregroundcolor green 

  $web.Dispose()          
  $site.Dispose()          
 }


Update Existing SharePoint View with PowerShell:
#Function to Update Existing View
Function UpdateViewFilter()
 {  
  Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$ListName, [Parameter(Mandatory=$true)] [string]$ViewName, [Parameter(Mandatory=$true)] [string]$ViewQuery ) 
  $site = Get-SPSite $SiteURL
  $web = $site.openweb()
  #Get the List
  $list=$web.lists[$ListName]
  #Get the View
  $view = $list.Views[$ViewName]
  #Update the view
  if($view -ne $null)
  {
   $view.Query = $ViewQuery
   $view.Update()
   $list.update()
   #Send message to output console
   write-host "View $($ViewName) Updated Successfully!" -foregroundcolor green 
  }
  else
  {
   write-host "Could Not find: $($ViewName)!" -foregroundcolor red 
  }
  $web.Dispose()          
  $site.Dispose()          
 }

Copy SharePoint list view in PowerShell:
#Function to Update Existing View
Function CopyView()
 {  
  Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$ListName, [Parameter(Mandatory=$true)] [string]$SourceView, [Parameter(Mandatory=$true)] [string]$TargetView ) 
  $site = Get-SPSite $SiteURL
  $web = $site.openweb()
  #Get the List
  $list=$web.lists[$ListName]
  #Get the source View
  $view = $list.Views[$SourceView]
  #Copy the source view
  if($view -ne $null)
  {
   #Get View Fields from an existing view
    $Viewfields = $list.Views[$SourceView].ViewFields.ToStringCollection()
    #Set View options
    $viewRowLimit="100"
    $viewPaged=$true
    $viewDefaultView=$false
    $viewQuery="<Where><Eq><FieldRef Name='Document_x0020_Type' /><Value Type='Choice'>Customer Reconciliation</Value></Eq></Where>"

    #Crete new view
    $newview = $list.Views.Add($TargetView, $viewFields, $viewQuery, $viewRowLimit, $viewPaged, $viewDefaultView)

   #Send message to output console
   write-host "View $($SourceView) Copied Successfully!" -foregroundcolor green 
  }
  else
  {
   write-host "Could Not find: $($SourceView)!" -foregroundcolor red 
  }
  
  $web.Dispose()          
  $site.Dispose()          
 }

Delete SharePoint List View in PowerShell: 
#Function to Delete View
 Function DeleteView()
 {  
  Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$ListName, [Parameter(Mandatory=$true)] [string]$ViewName ) 
  $site = Get-SPSite $SiteURL
  $web = $site.openweb()
  #Get the List
  $list=$web.lists[$ListName]
  #Get the View
  $view = $list.Views[$ViewName]
  #Delte the view
  if($view -ne $null)
  {
   $list.Views.Delete($view.ID)  
   #Send message to output console
   write-host "View $($ViewName) Deleted Successfully!" -foregroundcolor green 
  }
  else
  {
   write-host "Could Not find: $($ViewName)!" -foregroundcolor red 
  }
  $web.Dispose()          
  $site.Dispose()          
 }
 
Added MOSS 2007 compatibility to support SharePoint 2007 environments
# For MOSS 2007 compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets

Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )

   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}
 
Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion

Once tested above snippets, placed them inside my PowerShell script, called those functions wherever required.
$WebURL="https://sharepoint.crescent.com/sites/finance/"

 #Get the Target Site
 $Web=Get-SPWeb $WebURL

foreach($List in $web.lists)
 {
  if ( ($List.BaseType -eq "DocumentLibrary") -and ($List.Hidden -eq $false) )
   {
   write-host "Processing List: $($list.title)"

    #Call funtion to create new view 
    CreateNewView $WebURL $List.title "Global Customers"

    #Call the Function to Delete view
    DeleteView $WebURL $List.title "Journal Vouchers"

    #Call function to Update existing view 
    UpdateViewFilter $WebURL $List.title "Vendor Reconciliation" "<Where><Eq><FieldRef Name='Document_x0020_Type' /><Value Type='Choice'>Vendor Reconciliation</Value></Eq></Where>"

    #Call function to copy existing view
    CopyView $WebURL $List.title "Vendor Reconciliation" "Customer Reconciliation"     
   }
 }

BTW, This is a PowerShell version of my existing work, where I did similar thing using .Net Object Model (C#).  How to Create Update Delete SharePoint Views Programmatically

SharePoint Users and Groups Permission Report

$
0
0
Requirement: For security audit purpose, had to generate a comprehensive users and groups security report for entire site collection. Some of the sub-sites, some of the lists & libraries are with unique permission.

Solution: Lets use PowerShell with little HTML & CSS to generate a users and groups permission Report!

On executing the PowerShell script, will generate a HTML file as in the below screen with:
  • Table of content for all Sub-sites in the site collection
  • List of site collection administrators
  • Users who has access on the site
  • Site's Groups granted access
  • Members of each group which has access to the site.
  • Lists with unique permissions and its users & groups.

Here goes our HTML template Code:
In run time, The data being generated will be merged with the HTML code to get a formatted report in HTML format.

<html><head><!-- Javascript goes in the document HEAD --><script type="text/javascript">
function altRows(id){
 if(document.getElementsByTagName){  
  var table = document.getElementById(id);  
  var rows = table.getElementsByTagName("tr"); 
  for(i = 0; i < rows.length; i++){          
   if(i % 2 == 0){
    rows[i].className = "evenrowcolor";
   }else{
    rows[i].className = "oddrowcolor";
   }      
  }
 }
}
window.onload=function(){
 altRows('alternatecolor');
}</script><!-- CSS goes in the document HEAD or added to your external stylesheet --><style type="text/css">
body{
font-family: Calibri; 
 height: 12pt; 
}
table.altrowstable {
 border-collapse: collapse; 
 font-family: verdana,arial,sans-serif;
 font-size:11px;
 color:#333333;
 border-width: 1px;
 border-color: #a9c6c9;
 border: b1a0c7 0.5pt solid; 
}
table.altrowstable th {
 border-width: 1px;
 padding: 5px;
 background-color:#8064a2;
 border: #b1a0c7 0.5pt solid;
 font-family: Calibri; 
 height: 15pt; 
 color: white; 
 font-size: 11pt; 
 font-weight: 700; 
 text-decoration: none;
}
table.altrowstable td {
 border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; color: black; font-size: 11pt; font-weight: 400; text-decoration: none; 
}
.oddrowcolor{
 background-color: #e4dfec;
}
.evenrowcolor{
 background-color:#FFFFFF;
}</style></head><body>

PowerShell Script to Generate Users and Groups Permission Report:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS 2007 Cmdlets 

 Function global:Get-SPSite($url)
 {
  if($url -ne $null)
     {
     return New-Object Microsoft.SharePoint.SPSite($url)
  }
 }
 
 Function global:Get-SPWeb($url)
 {
   $site= Get-SPSite($url)
         if($site -ne $null)
             {
                $web=$site.OpenWeb();
       
             }
     return $web
 }
 
#EndRegion

Function GenerateUserAccessReport()
{
 #Site Collection URL - Mandatory parameter
 param( [Parameter(Mandatory=$true)] [string]$SiteCollectionURL)

  #Get the site collection
  $Site= Get-SPSite $SiteCollectionURL
  #Append the HTML File with CSS into the Output report
  $Content=Get-Content -Path "table.htm" > PermissionReport.htm
 "<h2> $($Site.RootWeb.Title) - Users & Groups Permission Report</h2>" >> PermissionReport.htm 
  #Table of Contents
  "<h3> List of Sites</h3> <table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr><th>Site Name </th><th> URL </th></tr>" >> PermissionReport.htm
    #Get Users of All Webs : Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs) 
       {
    "<tr> <td> <a href='#$($web.Title.ToLower())'>$($web.Title)</a> </td><td> $($web.URL)</td> </tr>" >> PermissionReport.htm
    }
   #Site Collection Administrators Heading 
  "</table><br/><b>Site Collection Administrators</b>" >> PermissionReport.htm

  "<table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> PermissionReport.htm

  #Write CSV (TAB Separated File) Header
  "<th>User Account ID </th> <th>User Name </th></tr>" >> PermissionReport.htm 
    #Get All Site Collection Administrators
     $Site.RootWeb.SiteAdministrators | sort $_.Name | ForEach-Object   {  
   "<tr><td> $($_.LoginName) </td> <td> $($_.Name)</td></tr> " >> PermissionReport.htm
  }
    #Get Users of All Webs : Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs) 
       { 
      #Check if site is using Unique Permissions or Inheriting from its Parent Site!
      if($Web.HasUniqueRoleAssignments -eq $true)
   {
         "</table><br/><hr> <h3>Site: [ <a name='$($Web.Title.ToLower())'>$($Web.Title) </a> ] at <a href='$($web.URL)'>$($web.URL)</a> is using Unique Permissions. </h3>" >> PermissionReport.htm
   }
   else
   {
     "</table><br/><hr> <h3>Site: [ <a name='$($Web.Title.ToLower())'>$($Web.Title) </a> ] at <a href='$($web.URL)'>$($web.URL)</a> is Inheriting Permissions from its Parent Site.</h3>" >> PermissionReport.htm
   }
      #Get the Users & Groups from site which has unique permissions - TOP sites always with Unique Permissions
      if($Web.HasUniqueRoleAssignments -eq $True)
             {
           #*** Get all the users granted permissions DIRECTLY to the site ***
     "<b>Site Users and Groups</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> PermissionReport.htm
     "<th>Users/Groups </th> <th> Type </th><th> User Name </th> <th>Permissions</th></tr>" >> PermissionReport.htm
              foreach($WebRoleAssignment in $Web.RoleAssignments ) 
                  { 
         #*** Get  User/Group Name *****#
         $UserGroupName=$WebRoleAssignment.Member.Name
         #**** Get User/Group Type *****#
       #Is it a SharePoint Group?
        if($WebRoleAssignment.Member.LoginName -eq $NULL) 
        {
         $Type="SharePoint Group"
         $UserName=$WebRoleAssignment.Member.Name
         #Set Flag value for "Group Exists"
         $GroupExistsFlag=$true
        }
                        #Is it a SharePoint User Account or Domain Group?
        else
        {
            $UserName=$WebRoleAssignment.Member.LoginName
         #Is it a Domain Group?
         if($WebRoleAssignment.Member.IsDomainGroup)
         {
           $Type="Domain Group"
         }
         else #if($WebRoleAssignment.Member.LoginName)    
         {
           $Type="SharePoint User"
         }
        }

        #Get the Permissions assigned to Group/User
         $WebUserPermissions=@()
           foreach ($RoleDefinition  in $WebRoleAssignment.RoleDefinitionBindings)
           {
                           $WebUserPermissions += $RoleDefinition.Name +";"
                          }
       
        #Send the Data to Log file
        " <tr> <td> $($UserGroupName) </td><td> $($Type) </td><td> $($UserName) </td><td>  $($WebUserPermissions)</td></tr>" >> PermissionReport.htm
      }
     #****** Get the Group members *********#
       "</table></br> " >>PermissionReport.htm
       if($GroupExistsFlag -eq $true)
       {
        "<b>Group Users</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >>PermissionReport.htm
       foreach($WebRoleAssignment in $Web.RoleAssignments ) 
                   { 
        #Is it a SharePoint Group?
        if($WebRoleAssignment.Member.LoginName -eq $NULL)    
         {
            "<th>Group: $($WebRoleAssignment.Member.Name)</th></tr> " >> PermissionReport.htm 
                           foreach($user in $WebRoleAssignment.member.users)
                               {
           #Send the Data to Log file
           " <tr><td></td> <td> $($user.Name) </td><td> $($user.LoginName) </td><td> $($user.Email)</td><tr>" >> PermissionReport.htm
          }
         }
                     }
      }
      #Reset Group Exists Flag 
      $GroupExistsFlag=$false
     }
     #********  Check Lists with Unique Permissions ********/
              foreach($List in $Web.lists)
              {
      #Skip the Hidden Lists
                  if( ($List.HasUniqueRoleAssignments -eq $True) -and  ($List.Hidden -eq $false))
                  {
       "</table><br/><b>Users and Groups in List: [ $($List.Title) ] at <a href='$($List.ParentWeb.Url)/$($List.RootFolder.Url)'>$($List.ParentWeb.Url)/$($List.RootFolder.Url)</a> with Unique Permissions.</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> PermissionReport.htm
       "<th>Users/Groups </th><th>  Type </th><th> User Name </th><th> Permissions</th></tr>" >> PermissionReport.htm 
         #Get all the users granted permissions to the list
               foreach($ListRoleAssignment in $List.RoleAssignments ) 
                   { 
          #*** Get  User/Group Name *****#
          $UserGroupName=$ListRoleAssignment.Member.Name
        #**** Get User/Group Type *****#
       #Is it a SharePoint Group?
        if($ListRoleAssignment.Member.LoginName -eq $NULL) 
        {
         $Type="SharePoint Group"
         $UserName=$ListRoleAssignment.Member.Name
        }
                        #Is it a SharePoint User Account or Domain Group?
        else
        {
            $UserName=$ListRoleAssignment.Member.LoginName
         #Is it a Domain Group?
         if($ListRoleAssignment.Member.IsDomainGroup)
         {
           $Type="Domain Group"
         }
         else #if($ListRoleAssignment.Member.LoginName)    
         {
           $Type="SharePoint User"
         }
        }

        #Get the Permissions assigned to Group/User
         $ListUserPermissions=@()
           foreach ($RoleDefinition  in $ListRoleAssignment.RoleDefinitionBindings)
           {
                           $ListUserPermissions += $RoleDefinition.Name +";"
                          }
       
        #Send the Data to Log file
        "<tr><td>$($UserGroupName) </td><td> $($Type) </td><td> $($UserName) </td><td>  $($ListUserPermissions)</td></tr>" >> PermissionReport.htm
        }
        "</table>" >>PermissionReport.htm
                }
                }
    } 
                 "</body></html>" >>PermissionReport.htm
   }
#Call the function to Get Users & groups Report
GenerateUserAccessReport "http://sharepoint.crescent.com/sites/compliance"

Report output:
SharePoint Users and Groups Permission Report

SharePoint Users and Groups Security Report Based on Permission Levels

$
0
0
Getting insights on who has access to  SharePoint sites & lists and what level of permission has been granted on all over site collection is a frequent requirement in SharePoint governance. Because, out of the box security reporting is very limited, I wrote this PowerShell script to generate SharePoint users and groups security report based on permission levels.

This report helps great in auditing user access on various SharePoint sites, lists to resolve any potential security risks according to the compliance. With the report, we can quickly and accurately get insights, such as
  • Report provides information about the list of users and groups who have been assigned permissions in the SharePoint site.
  •  It displays the list of assigned users and groups, account type (SharePoint user, AD group or SharePoint group), owner and members of the group and permission levels. 
  •  Analyses permissions for users and groups on any site or list.  So, its easy to analyze what a user has access to what.
  • It also lists out Site Permission Levels with their permissions defined for each one of them.
  • Additionally, this report gives list Permissions information where lists are with unique permissions. 

PowerShell Script to generate SharePoint users and groups security report based on permission levels

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 #Region MOSS-2007-Cmdlets 

 Function global:Get-SPSite($url)
 {
  if($url -ne $null)
     {
     return New-Object Microsoft.SharePoint.SPSite($url)
  }
 }
 
 Function global:Get-SPWeb($url)
 {
   $site= Get-SPSite($url)
         if($site -ne $null)
             {
                $web=$site.OpenWeb();
       
             }
     return $web
 }
 
#EndRegion

Function GeneratePermissionReport()
{
 #Site Collection URL - Mandatory parameter
 param([Parameter(Mandatory=$true)] [string]$SiteCollectionURL)

  #Get the site collection
  $Site= Get-SPSite $SiteCollectionURL

  $web=$site.RootWeb
  
  #Get HTML File with CSS into the Output report
  $Content=Get-Content -Path "table.htm"  > PermissionReport.htm
   "<h2> $($Site.RootWeb.Title) - Permission Report</h2>" | out-file "PermissionReport.htm" -Append
  #Table of Contents
  "<h3> List of Sites under $($Site.RootWeb.Title)</h3> <table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr><th>Site Name </th><th> URL </th></tr>" >> PermissionReport.htm
    #Get Users of All Webs : Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs) 
       {
    "<tr> <td> <a href='#$($web.Title.ToLower())'>$($web.Title)</a> </td><td> $($web.URL)</td> </tr>" >> PermissionReport.htm
    }
    #Get Users of All Webs : Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs) 
       { 
      #Check if site is using Unique Permissions or Inheriting from its Parent Site!
      if($Web.HasUniqueRoleAssignments -eq $true)
   {
    "</table><br/><hr> <h3>Site: [ <a name='$($Web.Title.ToLower())'>$($Web.Title) </a> ] at <a href='$($web.URL)'>$($web.URL)</a> is using Unique Permissions. </h3>" >> PermissionReport.htm 
   }
   else
   {
       "</table><br/><hr> <h3>Site: [ <a name='$($Web.Title.ToLower())'>$($Web.Title) </a> ] at <a href='$($web.URL)'>$($web.URL)</a> is Inheriting Permissions from its Parent Site.</h3>" >> PermissionReport.htm 
   }
   if($Web.HasUniqueRoleAssignments -eq $true)
   {    
    "<b>Site Users and Groups</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'>" >> PermissionReport.htm 
       #Get the Role Assignments - (Users & Groups Granted access to the site) with each Role
     foreach($RoleDefinition in $Site.RootWeb.RoleDefinitions)
    { 
        #Write-Host $RoleDefinition.Name
     #Write Table Caption
     "<tr><th colspan='3'> <b>Permission Level: $($RoleDefinition.Name) <b> </th></tr>" >> PermissionReport.htm
     #Write Table Header
     "<tr> <td><b>Users/Groups </b></td> <td><b> Type </b></td> <td><b>User Name</b></td></tr>"  >> PermissionReport.htm

        foreach ($WebRoleAssignment in $web.RoleAssignments)
            {
       foreach($RoleDefinitionBinding in $WebRoleAssignment.RoleDefinitionBindings)
       {
       #If the current Role assignment contains the Site's Role Definition?
       if($RoleDefinitionBinding.Name -contains $RoleDefinition.Name)
       {
        #**** Get User/Group Type *****#
        #Is it a SharePoint Group?
        if($WebRoleAssignment.Member.LoginName -eq $NULL) 
        {
         $Type="SharePoint Group"
         $UserName=$WebRoleAssignment.Member.Name
         #Set Flag value for "Group Exists"
         $GroupExistsFlag=$true
        }
                        #Is it a SharePoint User Account or Domain Group?
        else
        {
            $UserName=$WebRoleAssignment.Member.LoginName
         #Is it a Domain Group?
         if($WebRoleAssignment.Member.IsDomainGroup)
         {
           $Type="Domain Group"
         }
         else 
         {
           $Type="SharePoint User"
         }
        }
        #Send Data to Report
        "<tr> <td> $($WebroleAssignment.Member.Name) </td><td> $($Type) </td><td> $($UserName) </td> </tr>"  >> PermissionReport.htm
       }
      }
     }
    }
      "</table></br> " >> PermissionReport.htm
     if($GroupExistsFlag -eq $true)
      {
       #**** Get All Members Group and its users ****
       "<b>Group Members</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> PermissionReport.htm
       foreach ($WebRoleAssignment in $web.RoleAssignments)
              {
         #Check if its a group
          if($WebRoleAssignment.Member.GetType().FullName -eq "Microsoft.SharePoint.SPGroup")
          {
           "<th colspan='2'><b>Group Name: $($WebRoleAssignment.Member.Name)<b></th></tr><tr><td><b>User ID</b></td><td><b>User Name</b></td></tr>" >> PermissionReport.htm
           foreach($User in $WebRoleAssignment.Member.users)
                                {
            "<tr><td> $($User.LoginName) </td><td> $($User.Name) </td></tr>" >> PermissionReport.htm
           }
          }
        }
         "</table> " >> PermissionReport.htm
      }
      #Reset Group Exists Flag 
      $GroupExistsFlag=$false
     }
     #*** Get All List & Library permissions with Unique Access ***#
       foreach($List in $Web.lists)
                {
        #Skip the Hidden Lists
                    if( ($List.HasUniqueRoleAssignments -eq $True) -and  ($List.Hidden -eq $false))
                    {
         "</table><br/><b>Users and Groups in List: [ $($List.Title) ] at <a href='$($List.ParentWeb.Url)/$($List.RootFolder.Url)'>$($List.ParentWeb.Url)/$($List.RootFolder.Url)</a> with Unique Permissions.</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" | Out-File PermissionReport.htm -Append
         "<td><b>Users/Groups </b></td><td> <b> Type </b></td><td><b> User Name </b></td></tr>"  >> PermissionReport.htm 
                      foreach($RoleDefinition in $site.RootWeb.RoleDefinitions)
         { 
          "<tr><th colspan='3'> Permission Level: $($RoleDefinition.Name)  </th></tr>" >> PermissionReport.htm
             #Get all the users granted permissions to the list
                   foreach($ListRoleAssignment in $List.RoleAssignments ) 
                      { 
           foreach($RoleDefinitionBinding in $ListRoleAssignment.RoleDefinitionBindings)
            {
             if($RoleDefinitionBinding.Name  -contains $RoleDefinition.Name)
              {
                #*** Get  User/Group Name *****#
                  $UserGroupName=$ListRoleAssignment.Member.Name
                #**** Get User/Group Type *****#
               #Is it a SharePoint Group?
                if($ListRoleAssignment.Member.LoginName -eq $NULL) 
                {
                 $Type="SharePoint Group"
                 $UserName=$ListRoleAssignment.Member.Name
                }
                                #Is it a SharePoint User Account or Domain Group?
                else
                {
                    $UserName=$ListRoleAssignment.Member.LoginName
                 #Is it a Domain Group?
                 if($ListRoleAssignment.Member.IsDomainGroup)
                 {
                   $Type="Domain Group"
                 }
                 else #if($ListRoleAssignment.Member.LoginName)    
                 {
                   $Type="SharePoint User"
                 }
                }
                #Send the Data to Log file
                "<tr><td>$($UserGroupName) </td><td> $($Type) </td><td> $($UserName) </td></tr>" >> PermissionReport.htm
                }
               }
            }
                  }
                   }
       }
     #Dispose web object
     $web.dispose()  
     } 
     #*** Get Site Collection Permission Levels & Their base Permissions ***#
       "</table> <h2> Site Collection's Permission Levels & Their Base permissions </h2><p>"   >>PermissionReport.htm
       $site.RootWeb.RoleDefinitions | Where-Object {$_.hidden -eq $false} | ForEach-Object {
        "<b>Permission Level Name:</b> $($_.Name) <br/> <b> Permissions: </b>$($_.BasePermissions) <br/></p>" >>PermissionReport.htm
       }
       "</body></html>" >>PermissionReport.htm
    #Dispose the objects
    $Site.dispose()
    }
#Call the function to Generate Report
GeneratePermissionReport "http://sharepoint.crescent.com"

Report Output:
SharePoint Users and Groups Security Report Based on Permission Levels

This script uses a HTML File to apply CSS style to the report. You can refer my existing post:  SharePoint Users and Groups Permission Report to get the HTML file (table.htm).

BTW, Crescent is my arbitrary domain!

How to Hide Home Tab / First Tab in SharePoint 2010

$
0
0
Ever wanted to Hide or Remove the Home Tab (or First Tab) from SharePoint Site's Top navigation Menu bar?
sharepoint hide home tab
How to Hide home tab in SharePoint 2010
How to do that? Site Settings >>  Navigation Settings? No! You won't get an option to remove Home tab (or First Tab) from Navigation there!

Solution:
Yes, We can Hide SharePoint site's Home tab by overriding CSS classes of the the Top Navigation:

CSS to Hide Home Tab in SharePoint 2010:
<style type="text/css"> 
.s4-tn li.static > a
{
   display: none !important;
}
.s4-tn li.static > ul a
{
   display: block !important;
}</style>

Place these styles in your Style Sheet preferably(CSS), / Master Page / Content Editor Web Part based on your requirement! and the result goes here: home tab hidden in SharePoint 2010 site.
how to hide home tab in sharepoint 2010
For MOSS 2007: 
Just grabbed the ID of Home tab with IE developer toolbar, and the CSS code to Hide Home tab in SharePoint 2007:

<style type="text/css"> 
#zz1_TopNavigationMenun0 {

display: none !important;

}
</style>

Get SQL Server Database Size, Location for all Databases

$
0
0

Here are the SQL Server queries to get all SQL Server database data file and log file Size, Location:
SELECT DB_NAME(database_id) AS [Database Name],
       Name AS [Logical Name],
       Physical_Name AS [Physical Name],
       (size*8)/1024 AS [Size - MB] 
 FROM sys.master_files WHERE database_id > 4 
This script outputs each data file & log file of all databases.

If you want to combine Data File & Log File Size:
SELECT DB_NAME(database_id) AS [Database Name], 
       SUM((size*8)/1024) [Size - MB] 
FROM sys.master_files 
WHERE database_id > 4 
group by DB_NAME(database_id) 
order by DB_NAME(database_id)

This will give you all Databases attached to a specific instance, excluding SQL Server system Databases like Master, Model, etc. (So we've: WHEREdatabase_id > 4)

Break Inheritance and Set Item Level or List Permission with PowerShell

$
0
0
Requirement is to Set Item Level permission to a SharePoint Group to all documents in a specific document library with 100+ documents.

Solution:  Earlier, I wrote C# code to set Item level permission on Event Receiver to Set Item Level Permissions . This time let me do it with PowerShell.

Set Item Level Permission with PowerShell
# For MOSS 2007 compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets
Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )

   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}
 
Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion

 Function AddItemLevelPermissionToGroup()
 {  
    #Define Parameters
    Param( [Parameter(Mandatory=$true)] [string]$SiteURL, 
           [Parameter(Mandatory=$true)] [string]$ListName, 
           [Parameter(Mandatory=$true)] [string]$GroupName,
           [Parameter(Mandatory=$true)] [string]$PermissionLevel )
 
 #Get the Web Application
    $Web=Get-SPWeb($SiteURL)
    
    #Get the List
    $list = $web.Lists[$ListName]
    if ($list -ne $null)  
    {  

    #Loop through each Item in the List
     foreach($item in $list.items)
   {
            #Check if Item has Unique Permissions. If not Break inheritence
            if($item.HasUniqueRoleAssignments -eq $False)  
              {  
               $item.BreakRoleInheritance($false)
               #False: Does removes all users & groups from Item's Permissions  
              } 
           if ($web.SiteGroups[$GroupName] -ne $null)  
               {
                #Get the Group from GroupName Parameter  
                $group = $web.SiteGroups[$GroupName]  
                $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)  
                #Get Permission Level, such as "Read", "Contribute", etc
                $roleDefinition = $web.RoleDefinitions[$PermissionLevel]
                $roleAssignment.RoleDefinitionBindings.Add($roleDefinition);  
                #Grant Access to specified Group
                $item.RoleAssignments.Add($roleAssignment)  
                #To Remove Access: Call  $item.RoleAssignments.Remove($group) . No Need for objects: roleAssignment, roleDefinition
                $item.SystemUpdate();  
                Write-Host "Successfully added $($PermissionLevel) to $GroupName group in $($Item.Name)" -foregroundcolor Green  
               }  

         }
  $Web.Dispose()          

    }
 }

#Call the Function to Grant Item Level Permission
#Parameters: $SiteURL, $ListName, $GroupName, $PermissionLevel
AddItemLevelPermissionToGroup "http://sharepoint.crescent.com/sites/sales" "Documents" "Approvers" "Read"

Similarly, We can add users to Item level/List permissions:
            #Add User to site, if doesn't exist
            $user = $web.EnsureUser('global\salaudeen')

            $roleDefinition = $web.RoleDefinitions[$PermissionLevel]

            $roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
            $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)

            $item.RoleAssignments.Add($roleAssignment)
            #Call $list.RoleAssignments.Add($roleAssignment) to set permission at List level
            $item.SystemUpdate();  
            Write-Host "Successfully added $($user) to $($Item.Name)" -foregroundcolor Green  

Create a Scheduled Task for PowerShell Script with Windows Task Scheduler

$
0
0
PowerShell is really a game changer for repeatable processes, isn't it? We've a PowerShell script to generate report on SharePoint content databases size growth SharePoint Content Databases Size - Storage Report, We used to run it on first day of every Month on SharePoint server to generate report.
Why don't we automate it with Windows Task scheduler? Sure! Lets create a scheduled task for PowerShell script with Windows task scheduler in windows server 2008 R2.

How to Create a Scheduled Task for PowerShell Script with Windows Task Scheduler
Here is how you can create Scheduled Tasks manually:

1. Start>> Administrative Tools>> Task Scheduler.  From Actions menu click on "Create a Basic Task"
windows task scheduler run powershell script
2. Give it a Name & Description Say: Content Databases Report, and click "Next"
windows task scheduler powershell script 
3. Select the interval you want to run the program. In my case, I chose "Monthly"
powershell script task scheduler windows 2008 r2

4. Specify the Months, Days in which the script to run. I've selected "All Months" and Day 1
schedule powershell script using task scheduler

5. In Action Tab, Select "Start a program" option button. Click Next
task scheduler to run powershell script 
6. In Start a Program Tab:
  • In Program/script, Enter: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • In Arguments, Enter the path of the script. Say: D:\Scripts\ContentDatabaseReport.ps1
  • In Start in, Enter the path where the script is located. say: D:\Scripts
powershell script scheduled task parameters
You must specify value for Start-in field, even though its optional. This is why because, if no value specified there, PowerShell will create the output in "C:\Windows\System32" directory.

7. Select the check box, "Open the Properties dialog for this task when I click Finish" and click Finish button.

8. Now, in the properties dialog, under the General tab, Make sure that the "Run when user is logged on or not" and "Run with highest privileges" check boxes are selected.
You will get a login prompt on clicking "OK" button. Enter the User Name & Password in which the task runs.

Create Tasks in Task Scheduler Command Line:
We can create scheduled task with the command line tool schtasks too!
schtasks /create /TN "Content Database Report" /SC monthly /mo 1 /ST 00:00 /RU "Domain\UserName" /RP "Password" /RL "HIGHEST" /TR "PowerShell D:\Scripts\ContentDatabaseReport.ps1" 

This will set the options "Run with highest privileges" and "Run whether the user is logged on or not"  for the Scheduled Task.

To Run the Scheduled Task on-demand:
  • Right click on the created task and choose Run.
  • switch over to the script file location and verify new report has been generated as an output from the script.
run scheduled task on demand

That's all! We've created a task in windows task scheduler for powershell script!

How to Edit SharePoint Survey "All Responses" View

$
0
0
By default, SharePoint Survey's "All Responses" view shows "View Response", "Created By", "Modified", "Completed" columns. There was a requirement to add one of the Survey answer to the view for easier categorization and filter. Unfortunately, There is no direct provision to edit Survey views as we edit any other list/library's view.

Typical, any edit view page goes like this: http://sharepoint-site/_layouts/ViewEdit.aspx?List={GUID OF THE LIST}&View={GUID OF THE VIEW}

So, What we need? Just List ID & View ID. That's it!

How to Get List GUID:
To Get Survey List ID: Go to "Settings >> Survey Settings" from List toolbar. Now, Right click any of the settings links, such as: Rating Settings or Validation Settings, etc and select "copy Shortcut" to Get the List ID. You will something similar to: http://sharepoint.crescent.com/_layouts/RatingsSettings.aspx?List={502aa2ee-8127-4929-ba58-c9b64ea77a2d} . So my survey list ID is: {502aa2ee-8127-4929-ba58-c9b64ea77a2d}

How to View GUID:
To Get View GUID: Go to view source of the All Responses page, Search for "View=" and copy the View's GUID

Here, I got something like: View={9B271D35-9428-4F8E-BB24-E10CB6EF4771}

Now, we've got the List ID and View ID. Hit this URL in the browser to get Edit View Page for All Responses!
http://sharepoint.crescent.com/_layouts/ViewEdit.aspx?List={502aa2ee-8127-4929-ba58-c9b64ea77a2d}&View={9B271D35-9428-4F8E-BB24-E10CB6EF4771}

It took me to normal view edit page, where I was able set filters, group and add any survey questions as columns.
Edit SharePoint Survey "All Responses" View
Update: Lately, Found an another shortcut! From "All Responses" page, Go to: Site Actions >> Edit Page >> Edit Survey Web Part >> Edit the current View to get the edit view page!

How to Add Custom File Type Icons in SharePoint

$
0
0
Problem: Photoshop files uploaded to the corporate branding portal was giving "JPEG" image icon and often caused confusion to end users!

Root cause: This is because of the DOCICON.XML file mapping in SharePoint. Out of the box, SharePoint 2010 has a icon for Photoshop files similar to JPEG Files. 

Fix: We've to change icon type in SharePoint 2010. Upload new icon for Adobe Photoshop files in 14 hive, update the DOCICON.XML file and Do a IISReset!

Steps in detail: How to Add Custom File Type Icons in SharePoint?
  1. Grab the Photoshop document icon (of name: psd.png) of 16x16 from the Internet. Copy to: 14 hive's Images folder: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES
  2. Take a backup and Update the DOCICON.XML, PSD Mapping key: with <Mapping Key="psd" Value="psd.png"/> under " <ByExtension>" Node
  3. Run IISReset from Command line console.
You have to do these steps in all your WFEs in multi-server farm!

Before Adding PSD Icon:
How to Add Custom File Type Icons in SharePoint
 After adding PSD Icons:
add adobe photoshop icon sharepoint 2010
Same issue occurred in an another case with Auto-CAD Files. Performed the above steps with Auto-cad Icon and fixed the issue by adding icon to SharePoint with new mapping key: <Mapping Key="dwg" Value="autocad.png"/>

Don't forget to do IISReset! Here is the before
sharepoint icon file types

and after screen shots: SharePoint custom icon for Autocad files
change icon in sharepoint 2010
Here is my old post on changing PDF Icon in SharePoint 2007: Change PDF Icon in SharePoint

Show Quick Launch in SharePoint 2010 Web Part Pages

$
0
0
By default, SharePoint 2010 Webpart pages don't have quick launch navigation! Web part page missing quick launch in SharePoint 2010. 
show quick launch sharepoint web part page
show quick launch in SharePoint web part page
Show quick launch SharePoint 2010 web part page:
We can bring it by editing web part page. Just Edit the webpart page in the SharePoint Designer 2010 Advanced Mode and remove the following code (As same in SharePoint 2007):
add quick launch to sharepoint web part page
<asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>

In SharePoint 2010 you have to also remove the following CSS code:
<style type="text/css">

body #s4-leftpanel
{
display:none;
}
.s4-ca

{
margin-left:0px;
}
</style>
sharepoint display quick launch web part page
Save the page! This will bring Quick launch bar again!! Here is the result: quick launch on SharePoint 2010 web part page.
sharepoint 2010 add quick launch menu to web part page
Here is my SharePoint 2007 version of this post: SharePoint 2007 Quick Launch (left navigation) Missing in Web part pages - Solutions

"There has been an error creating the personal site. Contact your site administrator for more information" - SharePoint My Site Creation Error

$
0
0
When end-user tries to create My sites by clicking "My Content" link for the first time, They encountered this error message:
"There has been an error creating the personal site. Contact your site administrator for more information"
There has been an error creating the personal site. Contact your site administrator for more information.

Troubleshooting:
1. Make sure User Profile Service Application & My Sites configuration is proper. Verify My Site Host Web Application is created with a Top level site collection of "My Site Host" Site Template.

2. Make sure Self Service Site creation is enabled for My site Host web application. Go to: Central Administration >> Application Management >> Manage Web Applications >> Select the My Site Host Web Application >> Click on "Self-Service Site Creation" from Ribbon >> Set it to "On". Otherwise, you will receive this error: "Your personal site cannot be created because Self-Service Site Creation is not enabled. Contact your site administrator for more information."
Your personal site cannot be created because Self-Service Site Creation is not enabled. Contact your site administrator for more information.


3. Make sure "personal" wildcard inclusion Managed path is added for My site host web application.
otherwise, you will get an error message: "Your personal site cannot be created because the managed path personal has not been created for this site. Contact your site administrator for more information."
Your personal site cannot be created because the managed path personal has not been created for this site. Contact your site administrator for more information.

4. Try Changing My site name format by going to: User Profile Service Application >> My Site Settings >> Setup My Sites >> Site Naming Format >> click either User name (resolve conflicts by using domain_username) or Domain and user name (will not have conflicts).

5. Make sure "Use Self-Service Site Creation" is enabled under My site host web application's User Permissions.
use self-service site creation in web application user permissions


6. Make sure the application pool of my site  web application is in Farm administrator group. Verify its a domain account and able to access the target domain.

7. Make sure "Create Personal Site" permission is enabled for "All authenticated Users" in User Profile Service Application's "Manage User Permissions"
Create Personal Site permission for All authenticated Users

8. Go to User Profile Service Application >> click on Setup My Sites under My Site Settings  >> Make sure Personal Site Location is set to "Personal" (which we verified in step 3)
sharepoint my site personal site location

9. In an another case: Found Event IDs 6141 and 5187 logged in Event Log.
Event ID 6141
The site /personal/domain_user could not be created.  The following exception occurred: Your changes could not be saved because this SharePoint Web site has exceeded the storage quota limit.
You must save your work to another location.  Contact your administrator to change the quota limits for the Web site..

Event ID 5187
My Site creation failure for user 'domain\user' for site url 'http://mysite.crescent.com/personal/domain_user'. The exception was: Microsoft.Office.Server.UserProfiles.PersonalSiteCreateException:

A failure was encountered while attempting to create the site. ---> Microsoft.SharePoint.SPException: Your changes could not be saved because this SharePoint Web site has exceeded the storage quota limit. You must save your work to another location.  Contact your administrator to change the quota limits for the Web site. ---> System.Runtime.InteropServices.COMException (0x80070718):
<nativehr>0x80070718</nativehr><nativestack></nativestack>Your changes could not be saved because this SharePoint Web site has exceeded the storage quota limit.
You must save your work to another location.  Contact your administrator to change the quota limits for the Web site.

Fix:
Check the Quota Template Limits: Verified "Personal" Quota Template has been set in My site web application's General Settings. To check the Personal Quota Template values, Navigated to: Central Admin>> Application Management>> Specify Quota Templates>> Personal >> Storage Limit values for maximum and warning was: 1 MB!!! (Not sure why!) I increased them to 100 MB and fixed this issue.

My Sites troubleshooting - Technet
http://technet.microsoft.com/en-us/library/gg750250%28v=office.14%29.aspx

SharePoint 2010 Content Editor Web Part Hidden property is Disabled

$
0
0

Found a interesting issue today. Wanted to place some CSS code in Content Editor Web Part (CEWP) and hide it, so that it won't appear to end-users. I added a content editor web part, Placed some CSS code, went to web part properties, oops! Hidden property under Layout is disabled (greyed out)!!
content editor web part Layout hidden property is disabled
SharePoint web part hidden disabled
Cause: For some reasons, SharePoint doesn't allow us to hide web parts on publishing pages! So Content Editor Web Part's Layout hidden property is disabled!!

Workaround:
Here is the workaround to fix SharePoint 2010 web part hidden grayed out: Just Append  ToolPaneView=2 to the URL to open the page in Edit mode. E.g. http://sharepoint.crescent.com/sitepages/home.aspx?ToolPaneView=2

This opens Add Web Parts Pane, from there we can add new CEWP to bottom zone of the page (Verified in SharePoint 2010 web part hidden property is not greyed out this time!) and  hide the web part with out any issue! 
sharepoint web part hidden disabled

Nintex Workflow "There was an error installing the content type required for the flexi task action"

$
0
0
Nintex Workflow was giving an error, when trying to publish: "There was an error installing the content type required for the Flexi-Task action. Please arrange for an Administrator to run the following command on the server: stsadm.exe  -o installfeature -n nintexworkflowcontenttypeupgrade For more information please contact support@nintex.com"
There was an error installing the content type required for the flexi task action. Please arrange for an Administrator to run the following command on the server: stsadm.exe  -o installfeature -n nintexworkflowcontenttypeupgrade For more information please contact support@nintex.com
I already ran that command: stsadm –o installfeature –n nintexworkflowcontenttypeupgrade, as in the error screen. it completed with "Operation completed successfully!" but still had the same error!!

Then I tried activating it:
stsadm -o activatefeature -name nintexworkflowcontenttypeupgrade -url http://sharepoint.crescent.com/sites/finance/ -force


and things are turned good!

Change SharePoint Site Title, Description and Icon (Logo) with PowerShell

$
0
0
Its not necessary to continue with the name and description Administrators provides during the creation of the site, isn't it?  Let's see how we can change SharePoint site's Title, Description and Icon (Logo) from SharePoint Interface as well as using PowerShell.

How to Change Logo from SharePoint Web Interface?

Go to Site Actions >> Site settings >> Click on Title, description, and icon Link under "Look and Feel", Change the name and description as per your requirements!
Change SharePoint Site Title, Description and Icon with PowerShell
Change SharePoint Site Title, Description and Icon with PowerShell
#Get the Web
$Web= Get-SPWeb "http://your-sharepoint-site.com" 

#Set the Title & Description
$Web.Title = "Marketing Portal" 
$Web.Description = "Marketing Portal" 

#You can change the Quick Launch/Treeview navigation also (If its not a Publishing site):
$Web.TreeViewEnabled = $True 

#Update the changes
$web.Update()

How to Change Logo in SharePoint 2010 Site
When we create SharePoint sites, it comes with a default logo image from: /_layouts/images/siteIcon.png(SharePoint applies this logo when LogoURL property is empty!) .We can change it to reflect our own branding, so that it can be easily recognized. I needed to apply new logo for all SharePoint sites during a corporate re-branding project.

Instead of manual way, I want to do this change with PowerShell script to update all site collection's Logo icons. Here is my quick PowerShell script to apply and verify the logo for all SharePoint sites:

#Get the Site
$web = Get-SPWeb "http://your-sharepoint-site.com"

#Set Site Logo Icon
$web.SiteLogoUrl = "http://your-sharepoint-site.com/SiteAssets/Corp-logo.png"

#Set Logo Description
$web.SiteLogoDescription = "Corporate Logo for Your Company"

#Update the changes
$web.Update()

Logo can be from any SharePoint Library (such as Assets Library), Make sure all users have read access to the Logo file. Or it can be from 14 Hive's Images Folder (Recommended!) "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES".Once uploaded, We can refer it by providing URL: /_layouts/images/YourLogo.png

Important: When you place Logo Inside Images folder, Make sure its inheriting security (Go to Logo file's Properties >> Security >> Advanced >> Make sure "Include Inheritable Permissions from this object's Parent" is selected. If not, Click on "Change Permissions" button and enable "Include Inheritable Permissions from this object's Parent")! otherwise, End-users may get Log-on prompts and page may stop loading.
If you have multiple servers in your farm, You must upload this Logo image in each Web Front End Server!

To Get Logo Information of entire web application:
Get-SPWebApplication "http://your-sharepoint-URL.com" | Get-SPSite | Get-SPWeb | 
 foreach { "Site "+ $_.Url + " Logo URL: " +  $_.SiteLogoUrl }

To Change Logo For All Sites in a Web Application:
Get-SPWebApplication "http://your-sharepoint-URL.com" | Get-SPSite | Get-SPWeb | 
  foreach { $_.SiteLogoUrl = "/_layouts/Images/Corp-Logo.png"; $_.Update() }

To Change Logo for All sites in a Site Collection:
Get-SPSite "http://your-sharepoint-URL.com" | Get-SPWeb | 
   foreach { $_.SiteLogoUrl = "/_layouts/Images/Corp-Logo.png"; $_.Update() }

Ideally, Its a best practice to apply Logos as part of Branding.

Export Import SharePoint Content Type using PowerShell

$
0
0
Requirement: Copy a Content Type from development environment to staging environment.

Solution Overview:
  1. Export site columns associated with the content type from the source site collection
  2. Export custom content data types from source site collection
  3. Import site columns from the exported site columns xml
  4. Re-Create custom content types programmatically with PowerShell in the target site collection.
Steps in detail:
To Export and Import Site columns associated with the particular content type, follow my post:  Export Import Site Columns with PowerShell

Export Import SharePoint Content Type using PowerShell
Once all fields of the particular content type is exported and imported, we can Export-Import Content types:

PowerShell Script to Export Content Type:

    #Get the Source Web
    $SourceWeb = Get-SPWeb "http://dev.crescent.com"
    #Create Export XML File
    $XMLFile = "C:\SiteContentTypes.xml"
    New-Item $XMLFile -type file -force
    #Wrap Content Type Schema XML inside <ContentTypes> Element 
    Add-Content $XMLFile "`n<ContentTypes>"

    #Export All Content types of specific Group to XML file
    $sourceWeb.ContentTypes | ForEach-Object {
        if ($_.Group -eq "Crescent Content Types") 
  {
     #Export Content Types to XML file
            Add-Content $XMLFile $_.SchemaXml
        }
    }
    #Closing Wrapper 
    Add-Content $XMLFile "</ContentTypes>"

    #Dispose the web object
    $SourceWeb.Dispose()

PowerShell Script to Import Content Type:
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
      #Get the Target Web
      $TargetWeb = Get-SPWeb "http://test.crescent.com"
    #Get the Content Type Schema from XML
    $XMLFile = "C:\SiteContentTypes.xml"  
    [xml] $CTypeXML = Get-Content($XMLFile)
    #Create Site Content Types
    $CTypeXML.ContentTypes.ContentType | ForEach-Object {

        #Create New Content Type object inheriting from parent
        $SPContentType = New-Object Microsoft.SharePoint.SPContentType ($_.ID,$TargetWeb.ContentTypes,$_.Name)
       
        #Set Content Type description and group
        $SPContentType.Description = $_.Description
        $SPContentType.Group = $_.Group
       
     #Get all field References from the XML
        $_.Fields.Field  | ForEach-Object {
  
   write-host $_.DisplayName
   #Add Fields Reference to the New content type
            if( !$SPContentType.FieldLinks[$_.DisplayName])
            {
                #Create a field link for the Content Type by getting an existing column
                $SPFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($TargetWeb.Fields[$_.DisplayName])
           
                #Check to see if column is Optional, Required or Hidden
                if ($_.Required -eq "TRUE") {$SPFieldLink.Required = $true}
                if ($_.Hidden -eq "TRUE") {$SPFieldLink.Hidden = $true}
           
                #Add column to Content Type
                $SPContentType.FieldLinks.Add($SPFieldLink)
            }
        }
       
        #Create Content Type on the site and update Content Type object
        $ct = $TargetWeb.ContentTypes.Add($SPContentType)
        $SPContentType.Update()
        write-host "Content type'" $ct.Name "'has been created"
    }

    $TargetWeb.Dispose()

Thanks to: http://get-spscripts.com/2011/01/export-and-importcreate-site-columns-in.html

Clicking Type Icon Selects the Row Instead of Opening the Document?

$
0
0
Issue: Clicking Type Icon Selects the Row Instead of Opening the Document?

Fix: Its a known issue! Microsoft released a KB article: http://support.microsoft.com/kb/2457975
Clicking Type Icon Selects the Row Instead of Opening the Document
In short: Copy Paste the below code as a file named: "fldtypes_docicon.xsl" and save it under 14 Hive folder of all WFEs:  \14\template\layouts\XSL\  and do an IISReset!

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" ddwrt:oob="true"><xsl:output method="html" indent="no"/><xsl:template ddwrt:dvt_mode="body" match ="FieldRef[@Name='DocIcon']" mode="Computed_DocIcon_body"><xsl:param name="thisNode" select="."/><xsl:param name="folderUrlAdditionalQueryString" select="''"/><xsl:choose><xsl:when test="$thisNode/@FSObjType='1'"><xsl:variable name="alttext"><xsl:choose><xsl:when test="starts-with($thisNode/@ContentTypeId, &quot;0x0120D5&quot;)"><xsl:value-of select="$thisNode/../@itemname_documentset"/>: <xsl:value-of select="$thisNode/@FileLeafRef"/></xsl:when><xsl:otherwise><xsl:value-of select="$thisNode/../@listformtitle_folder"/>: <xsl:value-of select="$thisNode/@FileLeafRef"/></xsl:otherwise></xsl:choose></xsl:variable><xsl:variable name="mapico" select="$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico"/><xsl:variable name="folderIconPath"><xsl:call-template name="GetFolderIconSourcePath"><xsl:with-param name="thisNode" select="$thisNode"/></xsl:call-template></xsl:variable><!-- This is a folder --><xsl:choose><xsl:when test="$RecursiveView='1'"><img border="0" alt="{$alttext}" src="{$folderIconPath}" /><xsl:choose><xsl:when test="$thisNode/@IconOverlay != ''"><img src="/_layouts/images/{$thisNode/@IconOverlay.mapoly}" class="ms-vb-icon-overlay" alt="" title="" /></xsl:when></xsl:choose></xsl:when><xsl:otherwise><xsl:variable name="FolderCTID"><xsl:value-of select="$PagePathFinal" />RootFolder=<xsl:value-of select="$thisNode/@FileRef.urlencode" /><xsl:value-of select="$ShowWebPart"/>&amp;FolderCTID=<xsl:value-of select="$thisNode/@ContentTypeId" />&amp;View=<xsl:value-of select="$View"/><xsl:value-of select="$folderUrlAdditionalQueryString"/></xsl:variable><a href="{$FolderCTID}" onmousedown ="VerifyFolderHref(this, event, '{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}', '{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}', '{$thisNode/@HTML_x0020_File_x0020_Type}', '{$thisNode/@serverurl.progid}')"
               onclick="return HandleFolder(this,event,&quot;{$PagePathFinal}RootFolder=&quot; + escapeProperly(&quot;{$thisNode/@FileRef}&quot;) + '{$ShowWebPart}&amp;FolderCTID={$thisNode/@ContentTypeId}&amp;View={$View}{$folderUrlAdditionalQueryString}','TRUE','FALSE','{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}','{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}','{$thisNode/@HTML_x0020_File_x0020_Type}','{$thisNode/@serverurl.progid}','{$thisNode/@CheckoutUser.id}','{$Userid}','{$XmlDefinition/List/@ForceCheckout}','{$thisNode/@IsCheckedoutToLocal}','{$thisNode/@PermMask}');"><img border="0" alt="{$alttext}" title="{$alttext}" src="{$folderIconPath}" /><xsl:choose><xsl:when test="$thisNode/@IconOverlay != ''"><img src="/_layouts/images/{$thisNode/@IconOverlay.mapoly}" class="ms-vb-icon-overlay" alt="" title="" /></xsl:when></xsl:choose></a></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><xsl:choose><xsl:when test="$IsDocLib"><a onfocus="OnLink(this)" href="{$thisNode/@FileRef}" onmousedown="return VerifyHref(this,event,'{$XmlDefinition/List/@DefaultItemOpen}','{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}','{$thisNode/@serverurl.progid}')"
   onclick="return DispEx(this,event,'TRUE','FALSE','{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}','{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}','{$thisNode/@HTML_x0020_File_x0020_Type}','{$thisNode/@serverurl.progid}','{$thisNode/@CheckoutUser.id}','{$Userid}','{$XmlDefinition/List/@ForceCheckout}','{$thisNode/@IsCheckedoutToLocal}','{$thisNode/@PermMask}')"><xsl:choose><xsl:when test="not ($thisNode/@IconOverlay) or $thisNode/@IconOverlay =''"><xsl:choose><xsl:when test="not ($thisNode/@CheckoutUser.id) or $thisNode/@CheckoutUser.id =''"><img border="0" alt="{$thisNode/@FileLeafRef}" title="{$thisNode/@FileLeafRef}" src="/_layouts/images/{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico}"/></xsl:when><xsl:otherwise><xsl:variable name="alttext"><xsl:value-of select="$thisNode/@FileLeafRef"/><xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&#10;</xsl:text><xsl:value-of select="$thisNode/../@managecheckedoutfiles_header_checkedoutby"/>: <xsl:value-of select="$thisNode/@CheckoutUser.title"/></xsl:variable><img border="0" alt="{$alttext}" title="{$alttext}" src="/_layouts/images/{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico}" /><img src="/_layouts/images/checkoutoverlay.gif" class="ms-vb-icon-overlay" alt="{$alttext}" title="{$alttext}" />                            </xsl:otherwise></xsl:choose>                  </xsl:when><xsl:otherwise ><img border="0" alt="{$thisNode/@FileLeafRef}" title="{$thisNode/@FileLeafRef}" src="/_layouts/images/{$thisNode/@IconOverlay.mapico}" /><img src="/_layouts/images/{$thisNode/@IconOverlay.mapoly}" class="ms-vb-icon-overlay" alt="" title="" /></xsl:otherwise></xsl:choose></a></xsl:when><xsl:otherwise><img border="0" src="/_layouts/images/{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico}"><xsl:attribute name="alt"><xsl:value-of select="$thisNode/@Title"/></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="$thisNode/@Title"/></xsl:attribute></img></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template></xsl:stylesheet>


Viewing all 1058 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>