Merge pull request #15 from Microsoft/pavanadepu2-patch-3

Removed the winrmconf.cmd dependency.
This commit is contained in:
Pavan Adepu 2017-12-26 17:15:48 +05:30 коммит произвёл GitHub
Родитель 3de2d7cdfb fa0e91878e
Коммит 5f861657bb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 20 добавлений и 29 удалений

Просмотреть файл

@ -9,7 +9,7 @@
param
(
[string] $hostname,
[string] $protocol="5986"
[string] $protocol
)
#################################################################################################################################
@ -29,9 +29,7 @@ $helpMsg = "Usage:
function Is-InputValid
{
param([string] $hostname)
{
$isInputValid = $true
if(-not $hostname -or ($protocol -ne "http" -and $protocol -ne "https"))
@ -59,10 +57,7 @@ function Delete-WinRMListener
function Configure-WinRMListener
{
param([string] $hostname,
[string] $protocol)
Write-Verbose -Verbose "Configuring the WinRM listener for $hostname over $protocol protocol"
Write-Verbose -Verbose "Configuring the WinRM listener for $hostname over $protocol protocol. This operation takes little longer time, please wait..."
if($protocol -ne "http")
{
@ -84,9 +79,6 @@ function Configure-WinRMHttpListener
function Configure-WinRMHttpsListener
{
param([string] $hostname,
[string] $port)
# Delete the WinRM Https listener if it is already configured
Delete-WinRMListener
@ -101,16 +93,16 @@ function Configure-WinRMHttpsListener
{
throw "Failed to create the test certificate."
}
}
}
# Configure WinRM
cmd.exe /c .\winrmconf.cmd $hostname $thumbprint
$WinrmCreate= "winrm create --% winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=`"$hostName`";CertificateThumbprint=`"$thumbPrint`"}"
invoke-expression $WinrmCreate
winrm set winrm/config/service/auth '@{Basic="true"}'
}
function Add-FirewallException
{
param([string] $protocol)
if( $protocol -ne "http")
{
$port = $winrmHttpsPort
@ -134,15 +126,8 @@ function Add-FirewallException
# Configure WinRM #
#################################################################################################################################
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=yes
winrm quickconfig
# The default MaxEnvelopeSizekb on Windows Server is 500 Kb which is very less. It needs to be at 8192 Kb. The small envelop size if not changed
# results in WS-Management service responding with error that the request size exceeded the configured MaxEnvelopeSize quota.
winrm set winrm/config '@{MaxEnvelopeSizekb = "8192"}'
# Validate script arguments
if(-not (Is-InputValid -hostname $hostname))
if(-not (Is-InputValid))
{
Write-Warning "Invalid Argument exception:"
Write-Host $helpMsg
@ -150,19 +135,25 @@ if(-not (Is-InputValid -hostname $hostname))
return
}
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=yes
winrm quickconfig
# The default MaxEnvelopeSizekb on Windows Server is 500 Kb which is very less. It needs to be at 8192 Kb. The small envelop size if not changed
# results in WS-Management service responding with error that the request size exceeded the configured MaxEnvelopeSize quota.
winrm set winrm/config '@{MaxEnvelopeSizekb = "8192"}'
# Configure WinRM listener
Configure-WinRMListener -hostname $hostname -protocol $protocol
Configure-WinRMListener
# Add firewall exception
Add-FirewallException -protocol $protocol
Add-FirewallException
# List the listeners
Write-Verbose -Verbose "Listing the WinRM listeners:"
$config = winrm enumerate winrm/config/listener
Write-Verbose -Verbose "Querying WinRM listeners by running command: winrm enumerate winrm/config/listener"
$config
winrm enumerate winrm/config/listener
#################################################################################################################################
#################################################################################################################################