Remotely Compiling Objects - Powershell
nick_robbo
Member Posts: 49
Hi, I am trying to write a Powershell script which will compile a selection of objects in our Development DB, before exporting them.
I am trying to make this part of a bigger script which we can then run for deployments.
Currently I get an error when using Invoke-Command to remotely compile the objects.
The error relates to not being able to Login to the SQL server, even if I use Get-Credential in the script block which is being run on the server.
Has anyone experienced this before? Or found a solution to this problem?
I am trying to make this part of a bigger script which we can then run for deployments.
Currently I get an error when using Invoke-Command to remotely compile the objects.
The error relates to not being able to Login to the SQL server, even if I use Get-Credential in the script block which is being run on the server.
Has anyone experienced this before? Or found a solution to this problem?
0
Answers
-
I use this code (NAV 2016 and up), that runs on the server where NAV is installed. The SQL server in my case is a separate server.
$cred = .....a PSCredentials Object, the user that runs the NAV Service and has access to the database ..... #Set up compiling servicetier New-NAVServerInstance -ServerInstance Compile -ManagementServicesPort 8900 -ClientServicesPort 8901 -SOAPServicesPort 8902 -ODataServicesPort 8903 -DatabaseServer $ServerName -DatabaseInstance $ServerInstance -DatabaseName $DatabaseName -ServiceAccount User -ServiceAccountCredential $cred Set-NAVServerInstance -ServerInstance Compile -Start #Compile objects Compile-NAVApplicationObject -DatabaseServer $ServerNameInstance -DatabaseName $DatabaseName -LogPath $OutputFolder -Recompile -SynchronizeSchemaChanges No -ErrorAction $ErrorActionPreference #Clean up after compilation Set-NAVServerInstance -ServerInstance Compile -Stop Remove-NAVServerInstance -ServerInstance Compile -Force
The CompileNAVApplicationObject cmdlet is imported using the NAV module "Microsoft.Dynamics.Nav.Model.Tools.psd1'' (in the RoleTailored Client folder)
Jan Veenendaal1 -
Thanks for your reply. Some of this is useful, I didn't realise you could create an instance just for compiling, then remove it. Cool idea.
I'm not sure if I explained my issue correctly, so I should probably include code examples...
This is the part of the script I am using, the first part updates the Version List, by running a codeunit. The second is the part where I am getting the error. (When trying to run "Compile-NAVApplicationObject")
This is the part where I am getting the error relating to logging in to the SQL server.Invoke-Command -ComputerName $ComputerName -Credential $Credentials -ArgumentList $Arguments, ` $FromServerInstance, $CodeunitIDToRun, $MethodName, $FromDatabaseName, $DatabaseServerName, $VersionListFilter -ScriptBlock { param( $Arguments, $FromServerInstance, $CodeunitIDToRun, $MethodName, $FromDatabaseName, $DatabaseServerName, $VersionListFilter ) Import-Module 'C:\Program Files\Microsoft Dynamics NAV\100\Service\NavAdminTool.ps1' -WarningAction SilentlyContinue -Scope Global -Force| Out-Null Import-Module 'C:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.NAV.Model.Tools.psd1' -WarningAction SilentlyContinue -Scope Global -Force | Out-Null Import-Module 'C:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Apps.Tools.psd1' -WarningAction SilentlyContinue -Scope Global -Force | Out-Null Invoke-NAVCodeunit -ServerInstance $FromServerInstance -CodeunitId $CodeunitIDToRun -MethodName $MethodName -Argument $Arguments Write-Host "Please supply credentials to allow object compilation.." -ForegroundColor Green $Credentials2 = Get-Credential if(!$Credentials2){exit} $ServerInstance = Get-NavServerInstance $FromDatabaseName Compile-NAVApplicationObject -DatabaseName $FromDatabaseName -DatabaseServer $DatabaseServerName ` -Filter $VersionListFilter -NavServerInstance $FromDatabaseName -SynchronizeSchemaChanges 'Yes' ` -Username $Credentials2.UserName -Password $Credentials2.Password }
0 -
I create a new servicetier because there usually is not a service available (I create a new database from a CRONUS backup, import all my objects as .txt from a TFS repository, and then I need to have a service tier to be able to compile)
The credentials that you use must be credentials of a user that has access to the database on SQL level - so maybe not a NAV user. I think this should be the same user account that is used to run the NAV service.Jan Veenendaal1 -
Yes I my user accound credentials have access at a SQL Level, I am working every day with this system through NAV and SQL. So I definitely have access, I am beginning to think this is a double-hop issue, and it can't pass my credentials again to the SQL Server, after already passing them to the Remote Computer.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
