SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am partially not even sure how to Google this question because whatever I type never seems to bring back any relevant search results.

I currently have a working script that is set to go through and change the auditing settings for each site collection. I am trying to find a way to EXCLUDE one site collection specifically.

Here is my code:

$spSites = Get-SpSite -Limit All
oreach ($spSite in $SpSites) {
write-host $spsite
$spsite.TrimAuditLog = $true 
#write-host $spsite.AuditLogTrimmingRetention
$spsite.AuditLogTrimmingRetention = 90
$SpSite.Audit.AuditFlags = [Microsoft.SharePoint.SPAuditMaskType]::Delete -bxor [Microsoft.SharePoint.SPAuditMaskType]::update -bxor [Microsoft.SharePoint.SPAuditMaskType]::SecurityChange

We have a 1 site collection set up for MySites. I would like to exclude this site collection but am not sure how to go about doing so. Any help would be greatly appreciated! And as always, thank you in advance! You guys have been insanely helpful on my sharepoint journey!

share|improve this question
A word of advice, before you test the "exclude" function, comment out the actual update code and replace it with debug code like writing the Url of the site - to confirm it has excluded mysites. :) – Russell Feb 19 '13 at 23:43
up vote 3 down vote accepted

Just filter your logic based on some property of your MySite like this:

if ($spsite.Url -ne "") {
   ... audit code ...
share|improve this answer
thanks, Dave! Ill give this a shot tomorrow when I am back in the office. – Kevin Feb 19 '13 at 21:43
Forgot to flag this one as the solution I went with. Worked like a charm, thanks for helping out a powershell green pea! – Kevin Mar 13 '13 at 18:32

You can specify a filter while retrieving the Site collection list from Get-SPSite:

$spsites = Get-SPSite -Filter { $_.Url -ne "" }

The Filter parameter is described here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.