Sep 13, 2016

Add New Users Dynamics NAV 2013,2013 R2, 2015, 2016


This Powershell Script can insert multiple users to Dynamics NAV DB at once. 


  • Start "Windows PowerShell ISE" with Administrator permissions.
  • Copy following script from start to end & past in "Script Pane".
  • If "Script Pane" is not visible go to View -> "Show Script Pane"




  • Add User Name(s) & NAV Service Instance.
  • Separate User Names with Commas. 
    • $WindowsUser = "<Domain>\<User>","<Domain>\<User>"
    • $ServerInstance = "<Instencs Name>"
  • Set the path to NavAdminTool.
    • import-module "C:\Program Files\Microsoft Dynamics NAV\90\Service\NavAdminTool.ps1"
  • Run the script.


#*** Script Start ***

#All the user names seperated with comas eg:"Amy","Bob","Candice".
$WindowsUser = "<Domain>\<User>","<Domain>\<User>"

#NAV Service Instance Name.
$ServerInstance = "<Instencs Name>"

#Clear Error Log
$Error.Clear()

#Show which of the four execution policies is currently in-force.
Get-ExecutionPolicy -List

#Set Current user policie to RemoteSigned. 
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

#Import NavAdminTool to get DB information.
import-module "C:\Program Files\Microsoft Dynamics NAV\90\Service\NavAdminTool.ps1"

#Insert each user with SUPER permission.
$UserCount = 0
ForEach ($User in $WindowsUser)
{
  New-NAVServerUser -ServerInstance $ServerInstance -WindowsAccount $User -LicenseType Full -State Enabled -ErrorAction "SilentlyContinue"
  New-NAVServerUserPermissionSet -PermissionSetId SUPER -ServerInstance $ServerInstance -WindowsAccount $User -ErrorAction "SilentlyContinue"     
  $UserCount += 1
}
Write-Host "`n *** Output *** `n"

#Show Errors
$ErrorCount = 0
ForEach($Message in $Error)
{
    $ErrorCount += 1
    Write-Host "Error message $ErrorCount"
    write-host "$Message"
    write-host "*********************************"
}
if ($ErrorCount -eq 0)
{
    Write-Host "`n"
    Write-Host "$UserCount user(s) inserted."

else
{
    Write-Host "`n"
    Write-Host "Completed with $ErrorCount error(s)."
}

#*** Script End ***

No comments:

Post a Comment