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){
    $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


-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


Do you also have access as a site collection owner? My experience is that it is not sufficient with permission through Add-SPShellAdmin. You need to have site collection administrator permissions on the current site collection as well.

  • This does not answer the question as per the StackExchange standards. Please check How to Answer. If you are facing any issue with your code then you can ask a new question describing your problem. Check How to Ask – Yash Saraiya Dec 29 '16 at 14:41
  • Hi! I realized that. I tried to "add a comment" on the original post but I got a message that "You must have 50 reputation to comment". So my only way to reply, that I found, to this post was via "Answer". How should I otherwise have done to participate in this discussion? I also tried to find how to send this as a private message to you @YashSaraiya , but I could not find a way through this forum. I'm quite new to this... – GlennMmo Dec 30 '16 at 8:33
  • Yes. That's absolutely true and that's why it's important to gain trust of this forum by involving yourself and gaining reputation points first. That's the only reason why I haven't down-voted your answer which if a user with sufficient reputation points would have suffered from. – Yash Saraiya Dec 30 '16 at 13:16
  • Ok, thank you for your respons @YashSaraiya Now I understand. Feel free to erase this dialogue about comments/answers if you have that access. – GlennMmo Jan 2 '17 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.