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.
NOT….
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:
-
Remove the application in IIS:
You’ll notice that the icon before “WebClient” changes.
-
Remove the folder in IIS:
-
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 { [cmdletbinding()] param( [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [String]$WebServerInstance, [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$false)] [int]$ProductVersion = 80 ) begin{} Process{ $CurrentWebServerInstance = Get-NAVWebServerInstance -WebServerInstance $WebServerInstance if (-not $CurrentWebServerInstance) { Write-Error "'$WebServerInstance' does not exist as a Web Server Instance." break } $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 /site.name:$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 /vdir.name:$WebSiteName/$webApp/WebClient/Resources/ExtractedResources & $AppCmd delete vdir /vdir.name:$WebSiteName/$webApp & $AppCmd delete app /app.name:$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) } } } } End{} }
1 comment
2 pings
That was helpful – thank you!
[…] Continue reading » […]
[…] Bron : Waldo’s Blog Lees meer… […]