Start Dynamics NAV Windows Client (RTC) from PowerShell
After my sessions during “conference season”, I promised to blog about my scripts. I decided to do this on small pieces of scripts .. and this one is so useful, though I only realised it was useful until I wanted to do a gimmick during a script. I’m actually using it all the time now :-).
In short …
When playing around with PowerShell, you might want to create testing environments and such by very simply:
- Restoring a backup
- Create a service tier
-
Do whatever you want to do with it, for example:
- turn it into a MultiTenant environment
- Use it to upload objects to start solving conflicts of a merge
- …
- turn it into a MultiTenant environment
It is just useful to, at the end of your script, start your Windows Client right away, to not loose time in trying to figure out the “connection string” and such.. .
And it’s simple to do so in PowerShell
I’m using the fact that it’s possible to start NAV with a shortcut like “DynamicsNAV://”… . This way, it as easy as opening any URL from PowerShell.
I wrote a small function that covers it .. :
function Start-NAVWindowsClient
{
[cmdletbinding()]
param(
[string]$ServerName,
[int]$Port,
[String]$ServerInstance,
[String]$Companyname,
[string]$tenant='default'
)
if ([string]::IsNullOrEmpty($Companyname)) {
$Companyname = (Get-NAVCompany -ServerInstance $ServerInstance -Tenant $tenant)[0].CompanyName
}
$ConnectionString = "DynamicsNAV://$Servername" + ":$Port/$ServerInstance/$MainCompany/?tenant=$tenant"
Write-Verbose "Starting $ConnectionString ..."
Start-Process $ConnectionString
}Simply start the “url” with “Start-Process” and off you go.. .
Enjoy!
Ps, there is even a gimmick within this gimmick: look at the way the company is handled. When there is no provided with the function, the script will try to find the “first” CompanyName by doing this oneliner:
(Get-NAVCompany -ServerInstance $ServerInstance)[0].CompanyName
How cool is that? ![]()
This was originally posted here.

Like
Report
*This post is locked for comments