I'm trying to manage my IIS instance through PowerShell.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") | Out-Null
$Iis = [Microsoft.Web.Administration.ServerManager]::OpenRemote($WebServer)
$IisApp = $Iis.sites[$SiteName].Applications["/$WebApplicationName"]
if(-not $IisApp)
{
$IisApp = $Iis.sites[$SiteName].Applications.Add("/$WebApplicationName", $WebApplicationFolder)
}
This fails because it finds the wrong IIS instance on the target machine sometimes. How do I tell Microsoft.Web.Administration
to use the real IIS and not IIS Express?
I've also tried fetching the latest Microsoft.Web.Administration
through NuGet and it does no better. I've pulled down the assembly into a shared Nuget location (c:\nuget\packages\
) and instead I load the assembly from there
add-type -Path "C:\nuget\packages\Microsoft.Web.Administration\lib\netstandard1.5\Microsoft.Web.Administration.dll"
and confirmed that ServerManager is coming from the correct assembly and it's no different.
I've uninstalled IIS Express from my machine and it works on my machine, but I can't uninstall IIS Express from every machine I wish to target.
How do I tell Microsoft.Web.Administration
to focus on real IIS instead of IIS Express?
If IIS Express is installed, everything fails. If IIS Express is not installed, everything is fine.
Help?
Loading the Microsoft.Web.Administration from C:\Windows\System32\inetsrv
fixed it. Remote invocation using OpenRemote
doesn't work, so I had to use Invoke-SqlCommand
to administer on remote machine.