Welcome to the navigation

Do qui reprehenderit excepteur in eu ex velit amet, culpa labore veniam, ullamco laboris adipisicing sint non in nulla voluptate consequat, ut ad enim sit. Non lorem velit nostrud enim eu culpa proident, nulla qui sed sit incididunt cupidatat ea sint duis eiusmod quis aliquip exercitation dolor consequat, et consectetur

Yeah, this will be replaced... But please enjoy the search!

Configure IIS Remote Management using PowerShell

I needed to activate the IIS Web Management Service (WMSvc) on some Windows 2012 R2 servers running Server Core to enable the remote management of IIS. 

This was done using PowerShell (as usual). There are two scripts in this post, they are both the same but the second one use a wrapper to perform the configuration remotely.

Local

# Get the service
$webManagementService = Get-Service WMSVC -ErrorAction Stop
 
# Stop the WMSVC, if running
if($webManagementService.Status -eq "Running") {
    Write-Host "WMSVC was running, stopping the service..." -ForegroundColor Yellow
    Stop-Service WMSVC
}
 
# Modify the EnableRemoteManagement property in the Windows Registry
$enableRemoteManagement = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name "EnableRemoteManagement"
if($enableRemoteManagement.EnableRemoteManagement -eq 0) {
    Write-Host "Setting the EnableRemoteManagement property" -ForegroundColor Yellow
    Set-ItemProperty HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name "EnableRemoteManagement" -Value 1 -ErrorAction Stop
    Write-Host "EnableRemoteManagement property set" -ForegroundColor Green
} else {
    Write-Host "The EnableRemoteManagement property was already set, skipping" -ForegroundColor Yellow
}
 
# Ensure automatic start of the WMSVC service
Write-Host "Starting the WMSVC service and enabling automatic startup" -ForegroundColor Yellow
Start-Service WMSVC
Set-Service WMSVC -StartupType Automatic
Write-Host "Service started and configured" -ForegroundColor Green
 
 
$port = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name "Port").Port
Write-Host "The Web Management Service is now configured running at port $port" -ForegroundColor Green

Remote

# setup
$server = "serveraddress"
 
# connect to server
$session = New-PSSession -ComputerName $server -Authentication Default
$job = Invoke-Command -Session $session -ScriptBlock { 
 
    # Get the service
    $webManagementService = Get-Service WMSVC -ErrorAction Stop
 
    # Stop the WMSVC, if running
    if($webManagementService.Status -eq "Running") {
        Write-Host "WMSVC was running, stopping the service..." -ForegroundColor Yellow
        Stop-Service WMSVC
    }
 
    # Modify the EnableRemoteManagement property in the Windows Registry
    $enableRemoteManagement = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name "EnableRemoteManagement"
    if($enableRemoteManagement.EnableRemoteManagement -eq 0) {
        Write-Host "Setting the EnableRemoteManagement property" -ForegroundColor Yellow
        Set-ItemProperty HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name "EnableRemoteManagement" -Value 1 -ErrorAction Stop
        Write-Host "EnableRemoteManagement property set" -ForegroundColor Green
    } else {
        Write-Host "The EnableRemoteManagement property was already set, skipping" -ForegroundColor Yellow
    }
 
    # Ensure automatic start of the WMSVC service
    Write-Host "Starting the WMSVC service and enabling automatic startup" -ForegroundColor Yellow
    Start-Service WMSVC
    Set-Service WMSVC -StartupType Automatic
    Write-Host "Service started and configured" -ForegroundColor Green
 
 
    $port = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name "Port").Port
    Write-Host "The Web Management Service is now configured running at port $port" -ForegroundColor Green
 
} -AsJob
 
# output
do {
    Receive-Job -Job $job
} while ($job.HasMoreData)

Test

You should now be able to connect to your IIS server using the remote tools.

Enjoy

Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author