Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am getting this error:

+ CategoryInfo: NotSpecified: (:) [CheckSiteCollection], TargetInvocationException
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException,CheckSiteCollection

when I do this:

foreach($webApp in Get-SPWebApplication) {
    DoSomething($webApp.Sites)
}

the error occurs at the DoSomething function. If I add a try catch around it, that stops the error message but it doesn't allow the script to go on.

The only time I get this message is when a site collection is set to "No Access" under the quota's page of central admin.

Question: how do I either skip sites that are locked with "No Access" or catch the error but allow the script to continue.?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Following URL should help you:
Check SharePoint 2010 Site Collection Locks with PowerShell

From the article above:

  • When UI value “No Access”
    ReadOnly = null
    ReadLocked = null
    WriteLocked = null

When No Access is set, that puts an explicit Deny permission on the site collection, which prevents the values from being read. Therefore it shows null values. Who wants to remember all that? How can we tie all this together and get a value for these easily?

 Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue

 $sites = get-spsite -limit all | foreach {
  write-host "Checking lock for site collection: " $_.RootWeb.Title -foregroundcolor blue
    if ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $false)
       { write-host "The site lock value for the site collection"$_.RootWeb.Title "is:  Unlocked" -foregroundcolor Green}
         if ($_.lockissue -ne $null) {
         write-host "The additional text was provided for the lock: " $_.LockIssue -foregroundcolor Green}
    elseif ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true)
       { write-host "The site lock value for the site collection"$_.RootWeb.Title "is:  Adding Content Prevented" -foregroundcolor Green}
   elseif ($_.ReadOnly -eq $true -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true)
      { write-host "The site lock value for the site collection"$_.RootWeb.Title "is:  Read-only" -foregroundcolor Green}
   elseif ($_.ReadOnly -eq $null -and $_.ReadLocked -eq $null -and $_.WriteLocked -eq $null)
      { write-host "The site lock value for the site collection"$_.RootWeb.Title "is:  No Access" -foregroundcolor Green}  

 }
share|improve this answer
    
thanks. that does the trick. I don't know how I didn't get this when I googled for it. –  Eonasdan Jan 23 '13 at 18:22
add comment

Your Answer

 
discard

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.