Archive for October, 2012

Changing the URL of SharePoint 2010 Sub-Site using PowerShell

October 17, 2012 1 comment

For whatever reason if you are unable to change the URL of a sub-site in SharePoint 2010 you can turn to PowerShell.

I ran into this issue when I tried to rename a subsite and received an error “The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator”

Get-SPWeb http://portal/subsite | Set-SPWeb -RelativeUrl newsubsitename

Setting SharePoint 2010 Audit Log Settings using PowerShell

October 17, 2012 9 comments

I needed to set the Audit Log settings for all the Site Collections in my SharePoint 2010 web application to prevent extensive database growth due to “over auditing”.  As many may know SharePoint 2010 audit logs can get out of hand if the logs are not monitored or trim accordingly, with extensive log growth in each content database which in return affects performance.

Instead of auditing everything on each Site Collection I only wanted to audit only specific events.

You can check with events can be audited in SharePoint 2010 –

I only wanted to audit these events (Editing Items, Deleting or restoring items, and Editing users and permissions), only have a 30 day retention period, and automatically trim the logs.

Below is the PowerShell script I created to set the Audit Log Settings for all Site Collections in my web application with the same audit settings.


function set-auditing {

$webapp = Get-SPWebApplication $URL
$auditmask = [Microsoft.SharePoint.SPAuditMaskType]::Delete -bxor [Microsoft.SharePoint.SPAuditMaskType]::Update -bxor [Microsoft.SharePoint.SPAuditMaskType]::SecurityChange

$webapp.sites | % {

$_.TrimAuditLog = $true
$_.Audit.AuditFlags = $auditmask
$_.AuditLogTrimmingRetention = 30

set-auditing http://portal


Since the Audit Log Settings can be changed by the Site Owners with Site Administration permissions, in our organization this setting can easily be changed by anyone with those permissions, so I placed this script in a Task Scheduler on my CA server and scheduled it to run on a daily basis to reset the settings back to my organizations policy just in-case it changed during the day.

Upgrade All SharePoint 2010 Content Databases Using PowerShell

October 5, 2012 Leave a comment

I recently blogged about how to upgrade your SharePoint 2010 Content Databases with Powershell when you see the status of the databases as such “Database is up to date, but some sites are not completely upgraded”

Now I wanted to be able to iterate through all the databases and update them all at once instead of having to manually update them one-by-one so I wrote a powershell script that goes through all databases and if an upgrade is needed it upgrades the database without any user interaction.

Below is the simple script you can use to accomplish this.


$waDBs = Get-SPWebApplication -Identity <URL of WebApplication>

foreach ($contentDB in $waDBs.ContentDatabases)

Write-Host “Upgrading…..” $contentDB
Upgrade-SPContentDatabase -id $contentDB -Confirm:$false