Create new user in Dynamics NAV 2015 using SQL Query and PowerShell Script

Hi Everyone,

In this article, I will explain how you can create a new user in Dynamics NAV 2015 on-premise when the user not able to access NAV.

For this example I will use 2 scripts the first script will be PowerShell script that will be used to get the WINDOWSSID, this SSID will be used in the second script that we have to execute on the DB.

PowerShell Script: Step - 1

===============================
"----------------------------------------------------
PowerShell Script: Step - 1: Get Windows SSID
-----------------------------------------------------"
$objUser = New-Object System.Security.Principal.NTAccount("domain","username")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value

S-1-5-21-1132629211-2723480886-917412543-1010

Use the resulted SSID in SQL Query Script.
===============================

SQL Query Script: Step - 2


===============================
-- -------------------------- --
-- SQL Query Script: Step - 2 --
-- -------------------------- --
DECLARE @USERSID uniqueidentifier, @WINDOWSSID nvarchar(119), @USERNAME nvarchar(50), @USERSIDTXT varchar(50)

SET @USERNAME = 'DOMAIN\username'
SET @USERSID = NEWID()
SET @USERSIDTXT = CONVERT(VARCHAR(50), @USERSID)
SET @WINDOWSSID = 'S-1-5-21-1132629211-2723480886-917412543-1010'

INSERT INTO [dbo].[User]
([User Security ID],[User Name],[Full Name],[State],[Expiry Date],[Windows Security ID],[Change Password],[License Type],[Authentication 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])
VALUES
(@USERSID,'SUPER','')
GO
===============================

The above script creates different entries in User, User Property, and Access Control tables.

Other important queries:
select * from [dbo].[User]
select * from [dbo].[User Property]
select * from [dbo].[Access Control]

Delete Query:
delete from [dbo].[User] where [User Security ID] ='6A294094-AF01-423B-A4FD-79A40F9B6392'
delete from [dbo].[Access Control] where [User Security ID] ='6A294094-AF01-423B-A4FD-79A40F9B6392'

 

Wallah!

I hope you understand how to create users for Dynamics NAV 2015 manually using SQL and PowerShell script.

Stay Tuned!

Add comment