@@ -1597,8 +1597,75 @@ if (!$restartingInstance) {
1597
1597
Add-LocalGroupMember -Group administrators -Member ' + $bcContainerHelperConfig.WinRmCredentials.UserName + '
1598
1598
}
1599
1599
' ) | Add-Content - Path " $myfolder \AdditionalSetup.ps1"
1600
+ }
1601
+ else {
1602
+ $UUID = (Get-CimInstance win32_ComputerSystemProduct).UUID
1603
+ ('
1604
+ if (!$restartingInstance) {
1605
+ Write-Host "Enable PSRemoting and setup user for winrm"
1606
+ Enable-PSRemoting | Out-Null
1607
+ Get-PSSessionConfiguration | Out-null
1608
+ pwsh.exe -Command "Enable-PSRemoting -WarningAction SilentlyContinue | Out-Null; Get-PSSessionConfiguration | Out-Null"
1609
+ $credential = New-Object PSCredential -ArgumentList "winrm", (ConvertTo-SecureString -string "' + $UUID + ' " -AsPlainText -force)
1610
+ New-LocalUser -AccountNeverExpires -PasswordNeverExpires -FullName $credential.UserName -Name $credential.UserName -Password $credential.Password | Out-Null
1611
+ Add-LocalGroupMember -Group administrators -Member $credential.UserName | Out-Null
1612
+ winrm set winrm/config/service/Auth '' @{Basic="true"}'' | Out-Null
1613
+ }
1614
+ ' ) | Add-Content - Path " $myfolder \AdditionalSetup.ps1"
1615
+ if ($bccontainerHelperConfig.useSslForWinRmSession ) {
1616
+ $additionalParameters += @ (" --expose 5986" )
1617
+ ('
1618
+ if (!$restartingInstance) {
1619
+ Write-Host "Creating self-signed certificate for winrm"
1620
+ $cert = New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName $env:computername -NotBefore (get-date).AddDays(-1) -NotAfter (get-date).AddYears(5) -Provider "Microsoft RSA SChannel Cryptographic Provider" -KeyLength 2048
1621
+ winrm create winrm/config/Listener?Address=*+Transport=HTTPS ("@{Hostname=""$env:computername""; CertificateThumbprint=""$($cert.Thumbprint)""}") | Out-Null
1622
+ }
1623
+ ' ) | Add-Content - Path " $myfolder \AdditionalSetup.ps1"
1624
+ }
1625
+ else {
1626
+ $additionalParameters += @ (" --expose 5985" )
1627
+ ('
1628
+ if (!$restartingInstance) {
1629
+ Write-Host "Allow unencrypted communication to container"
1630
+ winrm set winrm/config/service '' @{AllowUnencrypted="true"}'' | Out-Null
1631
+ }
1632
+ ' ) | Add-Content - Path " $myfolder \AdditionalSetup.ps1"
1633
+ }
1600
1634
1635
+ if (-not $bccontainerHelperConfig.useSslForWinRmSession ) {
1636
+ try {
1637
+ [xml ]$conf = winrm get winrm/ config/ client - format:pretty
1638
+ $trustedHosts = @ ($conf.Client.TrustedHosts.Split (' ,' ))
1639
+ if (-not $trustedHosts ) {
1640
+ $trustedHosts = @ ()
1641
+ }
1642
+ $isTrusted = $trustedHosts | Where-Object { $containerName -like $_ }
1643
+ if (! ($isTrusted )) {
1644
+ if (! $isAdministrator ) {
1645
+ Write-Host " $containerName is not a trusted host. You need to get an administrator to add $containerName to the trusted winrm hosts on your machine"
1646
+ }
1647
+ else {
1648
+ Write-Host " Adding $containerName to trusted hosts ($ ( $trustedHosts -join ' ,' ) )"
1649
+ $trustedHosts += $containerName
1650
+ winrm set winrm/ config/ client " @{TrustedHosts="" $ ( $trustedHosts -join ' ,' ) "" }" | Out-Null
1651
+ }
1652
+ }
1653
+ if ($conf.Client.AllowUnencrypted -eq ' false' ) {
1654
+ if (! $isAdministrator ) {
1655
+ Write-Host " Unencrypted communication is not allowed. You need to get an administrator to allow unencrypted communication"
1656
+ }
1657
+ else {
1658
+ Write-Host " Allow unencrypted communication"
1659
+ winrm set winrm/ config/ client ' @{AllowUnencrypted="true"}' | Out-Null
1660
+ }
1661
+ }
1662
+ }
1663
+ catch {
1664
+ Write-Host " Unexpected error when checking winrm configuration, you might not be able to connect to the container using winrm unencrypted"
1665
+ }
1666
+ }
1601
1667
}
1668
+
1602
1669
if ($includeCSide ) {
1603
1670
$programFilesFolder = Join-Path $containerFolder " Program Files"
1604
1671
New-Item - Path $programFilesFolder - ItemType Directory - ErrorAction Ignore | Out-Null
0 commit comments