Remove a “Dynamics NAV Web Client” (Remove-NAVWebServerInstance)

You might have run into this .. trying to remove a Web Server Instance, but not finding a corresponding PowerShell commandlet for that.

As you know, there are LOADS of PowerShell commandlets for server administration. But in the list, there is not a “Remove-NAVWebServerInstance”. This list kind of prooves it:

Is it forgotten? I don’t know… I guess so ..

But I can imagine that people want to remove a NAVWebServerInstance at a given point in time.. .

Do it Manually

Not being too familiar with IIS, it just went for:

  • Deleting the reference in IIS
  • Deleting the corresponding wwwroot folder

And thought that was it.


I forgot an important thing: removing the app. It comes down to removing the reference to your Web Server Instance in the “ApplicationHost” file, which can usually be found here: C:\Windows\System32\inetsrv\config\ . You’ll need to do that if you already removed it from IIS. If not removed from IIS? There is a trick you can do, without having to struggle through this file. That is removing the following in this particular order:

  1. Remove the application in IIS:

    You’ll notice that the icon before “WebClient” changes.

  2. Remove the folder in IIS:

  3. Remove the folder in wwwroot


With PowerShell

That’s too hard for me .. so I want a PowerShell CmdLet that helps me with this. I was lucky to find out there is a PowerShell ps1 script that you can find in this folder: C:\Program Files\Microsoft Dynamics NAV\80\Web Client\bin . There, you will find the “RemoveWebServerInstance.ps1”. I suppose this is used when you uninstall the Web Client. As this script will remove all WebServiceInstance, I changed it a bit, and turned it into a CmdLet-function, so it can be pipelined in to. Here it is .. Enjoy!


function Remove-NAVWebServerInstance
        [int]$ProductVersion = 80
        $CurrentWebServerInstance = Get-NAVWebServerInstance -WebServerInstance $WebServerInstance
        if (-not $CurrentWebServerInstance) {
            Write-Error "'$WebServerInstance' does not exist as a Web Server Instance."  
        $AppCmd = Join-Path (Get-Item "HKLM:\SOFTWARE\Microsoft\InetStp").GetValue("InstallPath") "\AppCmd.exe"
        $WebSiteName = (Get-Item "HKLM:\SOFTWARE\Microsoft\Microsoft Dynamics NAV\$ProductVersion\Web Client").GetValue("Name")
        $wwwRootPath = (Get-Item "HKLM:\SOFTWARE\Microsoft\InetStp").GetValue("PathWWWRoot")
        $webAppList = & $AppCmd list app /$WebSiteName | where{$_ -match $WebServerInstance }
        foreach ( $WebAppEntry in $webAppList )
            if ( $webAppEntry -match "APP `"$WebSiteName`/(?<content>.*)/WebClient.*" -eq $true)
                $webApp = $matches.Content
          $WebAppFolder = Join-Path $wwwRootPath $WebApp
                & $AppCmd delete vdir /$WebSiteName/$webApp/WebClient/Resources/ExtractedResources
                & $AppCmd delete vdir /$WebSiteName/$webApp
                & $AppCmd delete app /$WebSiteName/$webApp/WebClient
                if (Test-Path $WebAppFolder )
                    [System.IO.Directory]::Delete($WebAppFolder, $true)
                $webAppExtractedResourcesFolder = "$env:ProgramData\Microsoft\Microsoft Dynamics NAV\$ProductVersion\Web Client\$webApp" 
                if (Test-Path $webAppExtractedResourcesFolder )
                    [System.IO.Directory]::Delete($webAppExtractedResourcesFolder, $true)




5.00 avg. rating (98% score) - 2 votes

Permanent link to this article:

1 comment

2 pings

    • Davor on November 10, 2016 at 2:50 pm
    • Reply

    That was helpful – thank you!

  1. […] Bron : Waldo’s Blog Lees meer… […]

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.