Welcome to the navigation

In id dolore minim reprehenderit fugiat sed ex proident, tempor et quis nostrud amet, velit non dolore ipsum officia voluptate aliqua, laborum, cillum nisi in. Minim consequat, irure dolore velit et occaecat adipisicing in mollit nisi eu aute magna ut duis consectetur incididunt deserunt dolor lorem reprehenderit officia anim sit

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