Set Development Databases to Simple Recovery

If you develop SharePoint Solutions and have SharePoint installed in your development environment then this script will come in real handy to you.

This script uses a cursor and sets all non system databases to simple recovery. This will help you in terms of performance as it reduces the number of disk writes by SQL along with that you will not face the problem of SQL logs filling your hard drive.

USE MASTER
declare
@cmd varchar(2000),
@dbname varchar(64),
@logfile varchar(128)

declare c1 cursor for 
	SELECT  d.name, mf.name as logfile
	FROM sys.master_files mf
		inner join sys.databases d
		on mf.database_id = d.database_id
	where recovery_model_desc <> 'SIMPLE'
		and d.name not in ('master','model','msdb','tempdb') 
		and mf.type_desc = 'LOG'	
		
open c1
	fetch next from c1 into @dbname, @logfile
		While @@fetch_status <> -1
		begin
			select @cmd = 'ALTER DATABASE [' + @dbname + '] SET RECOVERY SIMPLE'
			exec(@cmd)
			select @cmd='USE [' + @dbname + '] checkpoint'
			exec(@cmd)
			select @cmd='USE [' + @dbname + '] DBCC SHRINKFILE ([' + @logfile + '], 1)'
			exec(@cmd)
			fetch next from c1 into @dbname, @logfile
		end
close c1
deallocate c1

You can also download the script here: SETDBSIMPLE

Disable Access Requests – SharePoint 2013

If you migrate from MOSS 2007 or SharePoint 2010 to SharePoint 2013, the access requests are enabled by default and are set to the email for the primary site collection administrator.

It can be a good thing if you want your end users to request access as needed but if you have more than 300 site collections which are centrally managed by a team of administrators managing thousands of users. It soon becomes a nightmare.

To avoid such scenarios, you can disable the Access Requests by a quick powershell script on the web application.

Below script sets the Access Request Email as none which inherently sets the “RequestAccessEnabled” to false.

There is no direct way to set this flag as it is exposed as a read only property.

$spsites = get-spsite -WebApplication  -Limit All
foreach($spsite in $spsites)
{
    foreach($SPweb in $spsite.AllWebs)
    {
        # if a site inherits permissions, then the Access request mail setting also will be inherited
        if (!$SPweb.HasUniquePerm)
        {
            Write-Host "Inheriting from Parent site";
        }   
        elseif($SPweb.RequestAccessEnabled)
        {
            $SPweb.RequestAccessEmail = "";
	    $SPweb.Update();
        }
    }
}