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

My goal is to retrieve all the alerts for a given domain user, in SP 2007, then delete these alerts.

I have referenced the following script on this site.

  • In DEV environment, when I run the script I receive an access denied error and the script deletes the alerts.
  • In Live environment, I receive the access denied error, but the script does not delete the alerts.

The access denied exception is:

The following exception was thrown when trying to enumerate the collection: "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))".

This exception happens when I loop the sites (webs) in a site collection. The line of code is:

$webs = $site.AllWebs
foreach ($web in $webs)
{...

Any ideas?

share|improve this question
add comment

5 Answers 5

up vote 2 down vote accepted

I suspect that your account doesn't have access to the SharePoint content databases.

Have a look at this support article which refers to stsadm but should also apply to Powershell.

When you use the UI / web services to interact with SharePoint, the connection to the content database is made under the security context of the app pool account. From console apps or scripts the connection is made under the context of the user account of the person running it.

Essentially you will need dbo permissions on the databases used by SharePoint: Farm Administrator access alone is not sufficient.

A look in the SharePoint ULS logs will probably reveal some further information.

Also see this Server Fault question

share|improve this answer
1  
You get my vote on this SHug. I tried all answers provided here. The answer you provided come closest to the solution that solved our problem. Basically, the farm admin was not the site administrator for each site collection, even though the central admin was saying that the farm admin is the site collection admin for each site collection. I know this doesn't follow MS best practices but the goal was to just make it work. – –  Hossein Aarabi Dec 22 '11 at 17:58
add comment

My guess is one or more Site Collections are in one of the following states:

  • Adding Content Prevented
  • Read-only
  • No Access

See http://technet.microsoft.com/en-us/library/cc263238%28office.12%29.aspx for instructions to unlock.

share|improve this answer
    
Thanks, you saved me. My $web.update() error appeared to be a locked site collection. After removing the lock I was able to perform the update() command. –  TempaC Nov 13 '12 at 10:05
add comment

You'll probably need to run your powershell script using an account that has appropriate access (eg farm administrator)

Alternately you could create a temporary authorization policy to allow a user full access to all sites and webs in order to carry out your maintenance

share|improve this answer
1  
I ran the script as a Farm Admin (Logged in to the SP Server as the Farm Admin, ran the PowerShell utility as an administrator). Can you direct me to a link or specify the steps for option #2? –  Hossein Aarabi Dec 13 '11 at 23:39
    
Hmmm, Daniel's answer may be on the right track. If that doesn't help, I'll update my answer. –  Paul Lucas Dec 14 '11 at 0:53
add comment

Is UAC enabled on the production server? If so you must use 'Run as administrator' and confirm in the pop-up...

share|improve this answer
add comment

You could try running your Powershell script in Web Application Pool account security context.

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.