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!

  • 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, 2013 at 23:43

2 Answers 2


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

if ($spsite.Url -ne "http://mysite.domain.com") {
   ... audit code ...
  • thanks, Dave! Ill give this a shot tomorrow when I am back in the office.
    – Kevin
    Feb 19, 2013 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, 2013 at 18:32

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

$spsites = Get-SPSite -Filter { $_.Url -ne "http://mysite.com" }

The Filter parameter is described here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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