Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With-windows-updates doesnt start WinRM service #314

Open
blschatz opened this issue Apr 5, 2022 · 7 comments
Open

With-windows-updates doesnt start WinRM service #314

blschatz opened this issue Apr 5, 2022 · 7 comments

Comments

@blschatz
Copy link

blschatz commented Apr 5, 2022

I've successfully uncommented the "WITHOUT .. UPDATES" and commented the "WITH .. UPDATES" stanzas in the windows 10 Autounattend.xml, and had packer successfully connect and orchestrate running scripts via winrm.

I've now reverted this to do updates, but winrm won't connect after the updates are installed. Looking at the provided Autounattend.xml, there's no stanza in the "WITH .. UPDATES" stanzas to re-enable winrm. Is it enabled in another way, or is this an omission?

I've tried copying the enable-winrm.ps1 SynconronousCommand stanza to after the win-updates.ps1 stanza, but it doesn't appear to get run. (Updates installed without issue).

Any suggestions the best way to achieve this?

Thanks!

@marcus3876
Copy link

marcus3876 commented May 11, 2022

Hi, I also observed a similar issue recently and do also not understand why enable-winrm.ps1 is only part of the "WITHOUT UPDATES" block. I had no time to investigate deeper, so only a thought: Have you increased the <order> value for "Enable WinRM" block (e.g. to 101) to make sure it is executed after win updates?

@goproslowyo
Copy link

@blschatz @marcus3876 the win-updates.ps1 script enables winrm after they finish or exceed the cycle count as far as I could tell this is the process.

See line #'s 36, 40, and 141 here.

@serard-bimandco
Copy link

The problem I face everytime is that the script fails at the end because it cannot get $connections

$Connections | ForEach-Object { $_.GetNetwork().SetCategory(1) }

@serard-bimandco
Copy link

When no update : everything is okay.

@serard-bimandco
Copy link

image

@serard-bimandco
Copy link

Following seems to fix the build with update :
@blschatz

try {
    $NetworkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
    $Connections = $NetworkListManager.GetNetworkConnections()
    $Connections | ForEach-Object { $_.GetNetwork().SetCategory(1) }
} catch {
    $_
}

try {
    Get-NetConnectionProfile | Where-Object NetworkCategory -eq "Public" | Set-NetConnectionProfile -NetworkCategory Private
} catch { 
    $_
}

Enable-PSRemoting -Force
winrm quickconfig -q
winrm quickconfig -transport:http
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="800"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/listener?Address=*+Transport=HTTP '@{Port="5985"}'
netsh advfirewall firewall set rule group="Windows Remote Administration" new enable=yes
netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" new enable=yes action=allow remoteip=any
Set-Service winrm -startuptype "auto"
Restart-Service winrm

When I up the vmware vagrant box, I get uninstalled updates :

image

@serard-bimandco
Copy link

I have ran it with 6h timeout and it ran well : it made me a vagrant box.
Not sure how to get all updates installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants