Created
September 6, 2017 12:00
-
-
Save duffney/294d49c20027d2aa7b94e5a451d0aa98 to your computer and use it in GitHub Desktop.
Enable-IISRemoteManagement.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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