Options

Create automatic user in nav when logging in the server

soetiesoetie Member Posts: 61
Hi all,

i was wondering if it is possible to do an automatic user creation by powershell, when a users loggs in for the first time.
Im having a demo environment which i refresh regular.

So can i when a user loggs in for the first time create a schedule script that makes the user "super"in nav automatically. So i dont have to add the user by hand?
It looks like MS does is also on its azure machines.

I have tried a bit with this:
--
Import-Module "${env:ProgramFiles}\Microsoft Dynamics NAV\80\Service\NavAdminTool.ps1"
# Add User
New-NavServerUser -WindowsAccount 'domain\user' -ServerInstance InstanceName
# Add Permission to the user
New-NavServerUserPermissionSet -WindowsAccount 'domain\user' -ServerInstance InstanceName -PermissionSetId SUPER

or maybe something like this,

# Add a NavUserPassword User who is SUPER
$user = Get-NAVServerUser $serverInstance | % { if ($_.UserName -eq $NavAdminUser) { $_ } }
if (!$user) {
New-NAVServerUser $serverInstance -UserName $NavAdminUser -Password (ConvertTo-SecureString -String $NavAdminPassword -AsPlainText -Force) -ChangePasswordAtNextLogOn:$false -LicenseType Full
New-NAVServerUserPermissionSet $serverInstance -UserName $NavAdminUser -PermissionSetId "SUPER"

But username, instance and also Computer name is constantly changing.

im running to several errors.Maybe someone could help?

Comments

  • Options
    kinekine Member Posts: 12,562
    I am using PS script which create users based on the selected OU in domain. You can schedule it or something to "refresh" the users in NAV based on users in your AD...
    Import-Module 'C:\Program Files\Microsoft Dynamics NAV\90\Service\Microsoft.Dynamics.Nav.Management.dll'
    $OUs= "ou=MyOU,ou=Users,ou=Company,dc=mydomain,dc=local",
            "ou=MyOU2,ou=Users,ou=Company,dc=mydomain,dc=local"
            
    
    foreach ($OU in $OUs) {
        $Users=Get-ADUser -Filter * -SearchBase $OU
        foreach ($User in $Users) {
          New-NAVServerUser -ServerInstance $serverInstance -WindowsAccount $User.UserPrincipalName
          New-NAVServerUserPermissionSet -ServerInstance $serverInstance -WindowsAccount $User.UserPrincipalName -PermissionSetId SUPER
        }
    }
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    soetiesoetie Member Posts: 61
    edited 2015-10-26
    Hi

    thanks, im gonna try it!
    oh no, i havent installed nav in a domain so im having only a local user.
    Maybe the best i will delete all users and wont add them in nav.
  • Options
    kinekine Member Posts: 12,562
    Than I am sure that you can read all local users through powershell too... :-) http://powershell.com/cs/media/p/2327.aspx
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.