acces denied when trying to get web.siteusers

I write a powershell script and when i try to get siteusers from certain SPWeb not all i have an access denied. My spweb object is correctly retrieve because i can display $web.Url

    $webapps = Get-SPWebApplication  $userToReplace = $null foreach($webapp in $webapps) {     if($userToReplace -ne $null){         break     }     $webappName = $webapp.DisplayName     Write-Output "webapp: $webappName"      foreach($sc in $webapp.Sites){              $siteUrl = $sc.Url               #Write-Output "siteUrl: $siteUrl"              $spsite = new-object Microsoft.SharePoint.SPSite($siteUrl)             $web = $spsite.openweb()             Write-Output $web.Url              $siteUsers = $web.SiteUsers              #here is empty and an exception with acces denied occurs when trying to loop throw the collection                 foreach($user in $siteUsers){                  Write-Output $user.LoginName                   }      } } 

-I've tried to put my code between elevated privilege but still doesn't workd

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({}); 

-I ran my script as administrator -I added policy on all web app with full control -I used command:

Get-SPShellAdmin | Add-SPShellAdmin -UserName domain\user 

Nothing of this solutions worked

Replay

Category: powershell Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 4.508 (s). 13 q(s)