SharePoint Server PowerShell scripts be structured and executed to ensure consistent results

James Wade Young 20 Reputation points
2026-01-14T08:13:48.5433333+00:00

Im using this script on SP2019 from the SharePoint Management Shell, some site collections are skipped, and others throw access-denied or object-not-found errors, even though the account running the script is a farm administrator

How can SharePoint Server PowerShell scripts be properly troubleshot and executed to ensure consistent behavior.

Microsoft 365 and Office | SharePoint Server | Development
{count} votes

Answer accepted by question author
  1. Steven-N 20,680 Reputation points Microsoft External Staff Moderator
    2026-01-14T10:52:56.2666667+00:00

    Hi James Wade Young

    Thank you for reaching out to Microsoft Q&A forum

    The root cause of this behavior is even though the script is executed using a farm administrator account in SharePoint 2019, it encounters “Access Denied” or “Object Not Found” errors on some site collections.

    Given this, I highly recommend you can try to run that cmdlet again right after applying these approaches below:

    Grant Full Control via Web Application Policy via using Central Administration to assign a Full Control policy to the script account for the target web application. This ensures consistent access across all site collections via Central Admin → Security → Configure Web Application User Policy

    Add the Account as Site Collection Administrator (SCA): If only a few site collections are affected, manually add the account as an SCA to those sites.

    Check for Locked or Inaccessible Sites Ensure no site collections are in a locked stateusing the Get-SPSite and Set-SPSite -LockState cmdlets.

    You can try the above approach, if the problem still persists, kindly let me know in the comments for further support.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".     

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.