Skip to content

Instantly share code, notes, and snippets.

@SQLtattoo
Last active May 5, 2020 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SQLtattoo/c73d16113c29154a0beb79c94fdbf0b2 to your computer and use it in GitHub Desktop.
Save SQLtattoo/c73d16113c29154a0beb79c94fdbf0b2 to your computer and use it in GitHub Desktop.
Manage NAV Application Server instances service state
function StartStopNSTs($action)
{
Import-Module "${env:ProgramFiles(x86)}\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1" -WarningAction SilentlyContinue | out-null
Import-Module "$env:ProgramFiles\Microsoft Dynamics NAV\100\Service\NavAdminTool.ps1" -WarningAction SilentlyContinue | Out-Null
Import-Module "${env:ProgramFiles(x86)}\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Apps.Tools.psd1" -WarningAction SilentlyContinue | Out-Null
$NSTs = Get-NAVServerInstance | Where-Object -Property 'State' -eq 'Running'
if(!$NSTs) {
Write-Output "No NSTs found"
}
else
{
$NSTsCnt = Get-NAVServerInstance | Where-Object -Property 'State' -eq 'Running' | Measure-Object
Write-Output "NSTs found in: $($NSTsCnt.Count)"
if($action -eq "running")
{
Write-Output $NSTs
return
}
Foreach ($NST in $NSTs)
{
if($action -eq "start")
{
$NST | Set-NAVServerInstance -Start
Write-Host "Starting $($NST.DisplayName)"
}
elseif($action -eq "stop")
{
$NST | Set-NAVServerInstance -Stop
Write-Host "Stopping $($NST.DisplayName)"
}
elseif($action -eq "restart")
{
$NST | Set-NAVServerInstance -Restart
Write-Host "Restarting $($NST.DisplayName)"
}
else
{
write-host "Unknown action"
}
}
}
}
## Make sure you don't run this in production carelessly
StartStopNSTs "running" #this is harmless :)
## Other flavors below...
# StartStopNSTs "start"
# StartStopNSTs "stop"
# StartStopNSTs "restart"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment