How I can impersonate a login with securityadmin server role On MSSQL 2008R2 I have two instances on different servers, and I need sync up the password changes for all logins.
I thing that i could create a store procedure where a user (impersonate) with securityadmin server role change the password.

Obs: CHANGE_PASSWORD is a user with securityadmin server role.

ALTER PROCEDURE SPU_CAMBIO_PASSWORD
(
    @USER VARCHAR(50),
    @PASSWORD VARCHAR(100)
)
WITH EXECUTE AS 'CHANGE_PASSWORD'
AS
    DECLARE @STATEMENT VARCHAR(200)
    SET @STATEMENT= 'ALTER LOGIN '+ @USER+ ' WITH PASSWORD = '''+@PASSWORD+''', CHECK_POLICY =OFF'
    EXEC(@STATEMENT)
GO


Error:
Cannot execute as the server principal because the principal "CAMBIO_PASSWORD" does not exist, this type of principal cannot be impersonated, or you do not have permission.
The bad news is that the EXECUTE AS clause (which you are using), as opposed to the statement, only works for Users (Database-level), and not Logins (Server-level).

BUT, the good news is that you don't need to use impersonation to solve this issue. Instead you need to use module signing, and you do that via the following steps (all done in [master]):


Create a Certificate (be sure to specify ENCRYPTION BY PASSWORD = 'password')
Create a Login from that Certificate
Grant that Login whatever permission you want, or add it to whatever Role is appropriate
Sign that Stored Procedure (i.e. SPU_CAMBIO_PASSWORD), after removing the EXECUTE AS clause
Backup that Certificate to files (a .cer file for the Certificate and a .pvk file for the Private Key). This is done so that it can be re-created later.
Remove the Private Key from that Certificate. This prevents anything else from being signed with it (so you better do that backup first!).


If that Stored Procedure is ever changed after signing it, the signature will be dropped automatically, thereby losing the association with those special permissions set up for that Certificate-based Login. This is a good thing as it allows you to do a code review (assuming you didn't make the change) before re-enabling the permissions. In this case, you would:


Restore the Private Key (using the same ALTER CERTIFICATE command that was used to remove the Private Key).
Sign the Stored Procedure
Remove the Private Key again