Skip to content

Instantly share code, notes, and snippets.

@duffney
Created September 6, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duffney/294d49c20027d2aa7b94e5a451d0aa98 to your computer and use it in GitHub Desktop.
Save duffney/294d49c20027d2aa7b94e5a451d0aa98 to your computer and use it in GitHub Desktop.
Enable-IISRemoteManagement.ps1
function Enable-IISRemoteManagement {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidateScript({
if (-not (Test-Connection -ComputerName $_ -Quiet -Count 1)) {
throw "The computer [$_] could not be reached."
} else {
$true
}})]
[ValidateLength(1,15)]
[string]$ComputerName
)
# Verify that the IIS Management Service Windows feature is installed.
if (Test-WindowsFeature -ComputerName $ComputerName -Name 'Web-Mgmt-Service') {
# Enable Remote Management via a Registry key.
$remoteKeyParams = @{
ComputerName = $ComputerName
Path = 'HKLM:\SOFTWARE\Microsoft\WebManagement\Server'
Name = 'EnableRemoteManagement'
Value = '1' }
Set-RemoteRegistryValue @remoteKeyParams
# Set the IIS Remote Management service to start automatically.
$setParams = @{
ComputerName = $ComputerName
Name = 'WMSvc'
StartupType = 'Automatic' }
Set-Service @setParams
# Start the IIS Remote Management service.
Get-Service -ComputerName $ComputerName -Name 'WMSvc' | Start-Service
}
else
{
throw 'IIS Management Service Windows feature is not installed.'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment