Disable and enable users in AX using T-Sql scripts

There are times when you need very fast to disable the users in AX, except of course one or two users logins. This is needed for instance when you are doing deployments of new code and you don't want users roaming free in your AX while you are not yet done.

Of course, you can try to use the Reject new logins but if you are restarting the AOS multiple times, that won't do it. So, the trick you can use is a very simple T-Sql script. Just open SSMS and run

UPDATE [UserInfo]
SET [Enable] = 0
WHERE [ID] NOT IN ('Admin', 'yourUserId') AND [NetworkAlias] NOT IN ('yourWinAlias') 

this will disable all the users logins except the ones that you require to perform the deployment tasks.

Of course you could also save the users that were previously disabled so they are not enabled in the last step. So you could do something like before running the above script

DROP TABLE [UserInfoDisabled]

SELECT [ID] INTO [UserInfoDisabled] FROM [UserInfo]
WHERE [Enable] = 0

When you are done just run

UPDATE [UserInfo]
SET [Enable] = 1
WHERE [ID] NOT IN (SELECT [ID] FROM [UserInfoDisabled])

No comments:

Post a Comment