How to invoke-navcodunit with navuserpassword

Question Status

Suggested Answer
ATester asked a question on 22 Mar 2018 1:17 PM

Hi

I am using powershell   to run a few navcodeunits but I am getting credential errors because my environment has been setup with navuserpassword authentication.  Is there a way to handle this without switching to windows credientials.

Here is the error: 

Invoke-NAVCodeunit NAV -CodeunitId 37044411 -MethodName rdSetupWarehouseEmployeesForAllLocationsWithDefaultLocationFromPowershell -Argument "TESTFORLONGNAME,Detroit"

Invoke-NAVCodeunit : The server has rejected the client credentials.

+ CategoryInfo : NotSpecified: (0:Int32) [Invoke-NAVCodeunit], FaultException`1

+ FullyQualifiedErrorId : MicrosoftDynamicsNavServer$NAV,Microsoft.Dynamics.Nav.Management.Cmdlets.InvokeNavCodeunit

Reply
Suggested Answer
Stefano Demiliani responded on 22 Mar 2018 4:10 PM

I don’t think it’s possible. You need to have the user under which you’re running the PowerShell script on NAV. You don’t need to switch to Windows authentication:

In your PowerShell script, first create the user in NAV with your Windows credentials (using New-NavServerUser) with the appropriate permissions. In this way you’ve A Windows user with the correct permissions in NAV. Then, run Invoke-NAVCodeunit.

Reply
Suggested Answer
ATester responded on 23 Mar 2018 4:31 PM

The suggestion on the link says: The solution was simply to create a new user (Windows authentication) and permission set for the Windows user running PowerShell. After creating this user I was able to run the codeunit. There is no need to create a separate NST handling Windows authentication.  

Unfortunately in Dynamics 365, I am not seeing a way to create a windows user.

Reply
Suggested Answer
Stefano Demiliani responded on 23 Mar 2018 4:35 PM

In my previous comment I’ve showed the solution that works for NAV 2018. What are you talking about?

Reply
Suggested Answer
Stefano Demiliani responded on 22 Mar 2018 4:10 PM

I don’t think it’s possible. You need to have the user under which you’re running the PowerShell script on NAV. You don’t need to switch to Windows authentication:

In your PowerShell script, first create the user in NAV with your Windows credentials (using New-NavServerUser) with the appropriate permissions. In this way you’ve A Windows user with the correct permissions in NAV. Then, run Invoke-NAVCodeunit.

Reply
Suggested Answer
Suggested Answer
Stefano Demiliani responded on 23 Mar 2018 4:35 PM

In my previous comment I’ve showed the solution that works for NAV 2018. What are you talking about?

Reply