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