4

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?

1
  • Just adding my two cents here... I fixed this issue by granting full control under the web application user policy.
    – user59097
    Aug 16, 2016 at 17:53

5 Answers 5

2

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

1
  • 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. –
    – H A
    Dec 22, 2011 at 17:58
3

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.

1
  • 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, 2012 at 10:05
1

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

0

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

2
  • 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?
    – H A
    Dec 13, 2011 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, 2011 at 0:53
0

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

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.