Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:08:43+00:00 2026-06-15T16:08:43+00:00

I have a Powershell script that executes in the context of a Windows user.

  • 0

I have a Powershell script that executes in the context of a Windows user. This user has a login on a SQL 2012 instance that is a member of the sysadmin server role.

I want the script to add another login on the SQL instance (which also has a corresponding Windows user) to the sysadmin server role.

To try this out in Management Studio (connected as SA), I’m using the following script:

execute as user = 'domain\currentsysadmin'

IF IS_SRVROLEMEMBER('sysadmin', 'domain\futuresysadmin') != 1
    ALTER SERVER ROLE [sysadmin] ADD MEMBER [domain\futuresysadmin]

revert

I have two issues here:

  1. When I run the script as it’s displayed here, the call to IS_SRVROLEMEMBER returns 0 as expected, but even though the domain\currentsysadmin login is a member of sysadmin, the call to ALTER SERVER ROLE returns:

    Msg 15151, Level 16, State 1, Line 8
    Cannot alter the server role ‘sysadmin’, because it does not exist or you do not have permission.

  2. When I run this in the context of SA without the EXECUTE AS statement, the ALTER SERVER ROLE statement appears to run successfully, but when I check the domain\futuresysadmin login, it is still not a member of the sysadmin role

How can I add the domain\futuresystem login to the sysadmin server role?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:08:44+00:00Added an answer on June 15, 2026 at 4:08 pm

    Use sp_addsrvrolemember:

    EXEC master..sp_addsrvrolemember @loginame = N'domain\futuresysadmin', @rolename = N'sysadmin'
    

    UPDATE:
    User context switching doesn’t inherit any server roles, like sysadmin. In reading the documentation: “Server-level permissions granted explicitly to identities in the user token or through role memberships are not honored.” When you switch user context, your user no longer has the right to grant sysadmin to another user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex Powershell script that gets run as part of a SQL
I have developed a Powershell script that needs to be run automatically daily. This
I have a Powershell script that calls sqlcmd to run a sql script that
I have a powershell script that will generate an email for users whose password
I have a function in a powershell script that is supposed to untar my
I almost have this Powershell script completed but I am stuck at the last
I've found a PowerShell script that can change the desktop wallpaper of my Windows
I have a powershell script that runs a console .exe application. The console application
I have a powershell script that runs fxcopcmd in the output window. Turns out
I have an engine that executes powershell scripts, and when they execute, need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.