Monday, March 7, 2016

Create super user in NAV 2016 using SQL Query

Following query will use to create new user in NAV 2016 database:

DECLARE @USERSID uniqueidentifier, @WINDOWSSID nvarchar(119), @USERNAME nvarchar(50)
SET @USERNAME   = 'DOMAINNAME\NILESHG'                           /*Domain Name\windowsid*/
SET @USERSID    =  NEWID();
SET @WINDOWSSID = 'S-1-5-21-3002391015-913717614-2845076***-****'   /* USER SID*/


INSERT INTO [dbo].[User]
           ([User Security ID],[User Name],[Full Name],[State],[Expiry Date],
                 [Windows Security ID],[Change Password],[License Type],[Authentication Email],[Contact Email])
    VALUES
          (@USERSID,@USERNAME,'',0,'1753-01-01 00:00:00.000',@WINDOWSSID,0,0,'','')

INSERT INTO [dbo].[User Property]
          ([User Security ID],[Password],[Name Identifier],[Authentication Key],[WebServices Key],[WebServices Key Expiry Date],[Authentication Object ID])
    VALUES
          (@USERSID,'','','','','1753-01-01 00:00:00.000','')

INSERT INTO [dbo].[Access Control]
           ([User Security ID],[Role ID],[Company Name],[Scope],[App ID])
    VALUES
          (@USERSID,'SUPER','',0,'00000000-0000-0000-0000-000000000000')

GO

====================================================================================

Get the SID of current login user by following command:
whoami /user

Get the SID of all domain user by following command:
wmic useraccount get name,sid

No comments:

Post a Comment