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 have been doing some testing in our labs for some new features we are working on. I purposely created some orphaned sites using a scenario I found in a blog and I ran into a strange side effect. What I did was use Remove-SPsite cmdlet to delete a certain site. I then ran the Restore-Spsite and wile this was in progress shut power to the machine. After successfully creating the orphaned site I ran the following:

foreach ($site in $sites)
{
       #$webs = $site | Get-SPWeb -Limit All
       $webs = $site.AllWebs
       foreach ($web in $webs)
}

in part of a script and when it came to the section where it went through the site collection with the orphaned site it stopped and threw up and exception error stating:

Failure Exception has been thrown by the target of an invocation.

I was able to correct the issue but was wondering if anyone else has seen this error as the result of an orphaned site when running cmdlets? Any information would be greatly appreciated. i know everyone is busy so thank you in advance for any feedback you have.

share|improve this question
add comment

1 Answer 1

Wrap your code with

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges( { 
   ...
})
share|improve this answer
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.