# Help with WinRM timeout issue

**URL:** <https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545>\
**Category:** Packer\
**Created:** [September 22, 2025, 6:01am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545 "2025-09-22T06:01:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 22, 2025, 6:01am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/1 "2025-09-22T06:01:29Z")

</div>

Hey guys, racking my brain trying to work out why my packer build is timing out at the winrm step, here is my HCL file config:

packer {

required\_plugins {

```
azure = {

  version = ">= 2.0.0"

  source = "github.com/hashicorp/azure"

}

```

}

}

source “azure-arm” “autogenerated\_1” {

azure\_tags = {

```
dept = "Build"

task = "Image deployment"

created-by = "Packer" 

OS_Version = "Windows 2019"

Release = "Latest"

```

}

# Azure Details

build\_resource\_group\_name = “RESOURCE NAME”

client\_id = “ID”

client\_secret = “SECRET”

subscription\_id = “SUB”

tenant\_id = “TENANT”

vm\_size = “Standard\_D2\_v2”

# Source Image Details

os\_type = “Windows”

image\_offer = “WindowsServer”

image\_publisher = “MicrosoftWindowsServer”

image\_sku = “2019-Datacenter”

# Managed Image Details

managed\_image\_name = “Win-2019-{{timestamp}}”

managed\_image\_resource\_group\_name = “RESOURCE GROUP”

# Network Settings

virtual\_network\_name = “VNET”

virtual\_network\_resource\_group\_name = “VNET\_GROUP”

virtual\_network\_subnet\_name = “SUBNET”

# Communicator Settings

communicator = “winrm”

winrm\_insecure = true

winrm\_timeout = “30m”

winrm\_use\_ssl = true

winrm\_username = “packer”

winrm\_password = “ComplexP@ssw0rd123!” "#This is an example#

custom\_data = base64encode(\<\<-EOF

```
<powershell>

\# Configure WinRM

Write-Host "Configuring WinRM..."

\# Create self-signed certificate for HTTPS

$cert = New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation Cert:\\LocalMachine\\My

$thumbprint = $cert.Thumbprint

\# Configure WinRM HTTPS listener

winrm create winrm/config/Listener?Address=\*+Transport=HTTPS "@{Hostname=\`"$env:COMPUTERNAME\`"; CertificateThumbprint=\`"$thumbprint\`"}"

\# Configure WinRM service

winrm set winrm/config/service '@{AllowUnencrypted="false"}'

winrm set winrm/config/service/auth '@{Basic="true"}'

winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="2048"}'

\# Configure firewall

New-NetFirewallRule -DisplayName "WinRM HTTPS" -Direction Inbound -Protocol TCP -LocalPort 5986 -Action Allow

\# Restart WinRM service

Restart-Service WinRM

</powershell>

EOF

```

)

}

build {

sources = [“source.azure-arm.autogenerated\_1”]

provisioner “powershell” {

```
inline = \[

  "Write-Host 'Installing IIS...'",

  "Add-WindowsFeature Web-Server",

  "Write-Host 'Waiting for Azure services...'",

  "while ((Get-Service RdAgent -ErrorAction SilentlyContinue).Status -ne 'Running') { Start-Sleep -s 5 }",

  "while ((Get-Service WindowsAzureGuestAgent -ErrorAction SilentlyContinue).Status -ne 'Running') { Start-Sleep -s 5 }"

\]

```

}

provisioner “powershell” {

```
inline = \[

  "Write-Host 'Running Sysprep...'",

  "& $env:SystemRoot\\\\System32\\\\Sysprep\\\\Sysprep.exe /oobe /generalize /quiet /quit /mode:vm",

  "while($true) { $imageState = Get-ItemProperty HKLM:\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Setup\\\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"

\]

```

}

}

The output get to just Waiting for VM to respond via WinRM. I have also tried via SSH, tried with and without SSL.

I tried with the “Administrator” account but that’s the default admin and can’t be used. Going to have gone grey at the end of this project.

Any insights would be greatly appreciated..

---

<div class="post-metadata">

**Author:** ![anurag.sharma](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/anurag.sharma/32/44067_2.png) [@anurag.sharma](https://discuss.hashicorp.com/u/anurag.sharma)\
**Post date:** [September 22, 2025, 6:57am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/2 "2025-09-22T06:57:49Z")

</div>

Does it work fine with the default Administrator account?

---

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 22, 2025, 8:07am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/3 "2025-09-22T08:07:13Z")

</div>

No, I tried to configure the Administrator account and it error’d also.

---

<div class="post-metadata">

**Author:** ![anurag.sharma](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/anurag.sharma/32/44067_2.png) [@anurag.sharma](https://discuss.hashicorp.com/u/anurag.sharma)\
**Post date:** [September 22, 2025, 8:46am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/4 "2025-09-22T08:46:11Z")

</div>

I’m guessing the WinRM service isn’t configured or running properly to let packer connect later.

Could you try experimenting with the `custom_data` and refer [this doc](https://developer.hashicorp.com/packer/docs/communicators/winrm#:~:text=A%20more%20complex%20example%20of%20a%20PowerShell%20script%20used%20for%20configuration%20can%20be%20seen%20below.).

Also to ensure if the custom\_data runs successfully, you can try to login into the VM and find the logs of this startup script to confirm no issues there.

---

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 22, 2025, 8:54am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/5 "2025-09-22T08:54:07Z")

</div>

The VM cleans itself up and deletes itself at the end or when it’s cancelled.

Let me try play with the custom\_data and revert.

---

<div class="post-metadata">

**Author:** ![anurag.sharma](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/anurag.sharma/32/44067_2.png) [@anurag.sharma](https://discuss.hashicorp.com/u/anurag.sharma)\
**Post date:** [September 22, 2025, 9:07am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/6 "2025-09-22T09:07:39Z")

</div>

Set the `winrm_timeout` to `1h` to give yourself some time to debug.

---

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 22, 2025, 10:06am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/7 "2025-09-22T10:06:27Z")

</div>

If I try and use Administrator as the username, if fails with this error:

==\> azure-arm.autogenerated\_1: ERROR: → InvalidParameter : The Admin Username specified is not allowed. For more information about disallowed usernames, see [Virtual Machines - Create Or Update - REST API (Azure Compute) | Microsoft Learn](https://aka.ms/vmosprofile)

---

<div class="post-metadata">

**Author:** ![anurag.sharma](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/anurag.sharma/32/44067_2.png) [@anurag.sharma](https://discuss.hashicorp.com/u/anurag.sharma)\
**Post date:** [September 22, 2025, 10:26am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/8 "2025-09-22T10:26:46Z")

</div>

Is the packer user created in the startup script? If no, then its probably why its failing.  
You can try this.

`# Create a new local administrator for Packer.`  
`$username = “packer”`  
`$password = ConvertTo-SecureString -String ‘password-here’ -AsPlainText -Force`  
`New-LocalUser $username -Password $password -FullName “Packer User” -Description “Temporary user for Packer”`  
`Add-LocalGroupMember -Group “Administrators” -Member $username`

---

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 23, 2025, 12:26am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/9 "2025-09-23T00:26:49Z")

</div>

It looks like it’s having trouble with this part of the code:

provisioner “powershell” {

```auto
inline = \[

  "New-LocalUser -Name 'packer' -Password 'PASSWORD' -FullName 'Packer User' -Description 'User for Packer build'",

  "Add-LocalGroupMember -Group 'Administrators' -Member 'packer'",

  "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine",

  "Write-Host 'Configuring WinRM...'",

  "winrm quickconfig -q",

  **"winrm set winrm/config/service '@{AllowUnencrypted=\\"true\\"}'",**

  **"winrm set winrm/config/service/auth '@{Basic=\\"true\\"}'",**

  "netsh advfirewall firewall add rule name =\\"WinRM-HTTP\\" dir=in action=allow protocol=TCP localport=5985",

  "netsh advfirewall firewall add rule name =\\"WinRM-HTTPS\\" dir=in action=allow protocol=TCP localport=5986",

  "Add-WindowsFeature Web-Server",

  "while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }",

  "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }",

  "& $env:SystemRoot\\\\System32\\\\Sysprep\\\\Sysprep.exe /oobe /generalize /quiet /quit",

  "while($true) { $imageState = Get-ItemProperty HKLM:\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Setup\\\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"

\]

```

}

The AllowUnencrypted and Basic authentication are both false when the VM is built. Is there a better syntax to do this?

---

<div class="post-metadata">

**Author:** ![anurag.sharma](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/anurag.sharma/32/44067_2.png) [@anurag.sharma](https://discuss.hashicorp.com/u/anurag.sharma)\
**Post date:** [September 23, 2025, 8:43am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/10 "2025-09-23T08:43:05Z")

</div>

Create the user during the startup script i.e inside the `custom_data` . The WinRM setup should also be done there.

The provisioning will take place only when the initial handshake with the VM has been successful.

---

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 23, 2025, 9:06am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/11 "2025-09-23T09:06:06Z")

</div>

The user is being created and winrm set during the source part:

# Communicator Settings

communicator = “winrm”

winrm\_insecure = true

winrm\_timeout = “60m”

winrm\_use\_ssl = false

winrm\_username = “Packer”

winrm\_password = “PASSWORD”

winrm\_port = “5985”

I don’t have a custom\_data area setup in my config yet.

source, then build and then provisioner. Where should I slot the custom\_data part in and how should that look as an example?

---

<div class="post-metadata">

**Author:** ![anurag.sharma](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/anurag.sharma/32/44067_2.png) [@anurag.sharma](https://discuss.hashicorp.com/u/anurag.sharma)\
**Post date:** [September 23, 2025, 1:23pm UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/12 "2025-09-23T13:23:34Z")

</div>

> [@phillip.atkins](#):
>
> custom\_data = base64encode(\<\<-EOF

I can see this as part of your hcl file, here’s where the winrm setup and account creation should be done.

---

<div class="post-metadata">

**Author:** ![phillip.atkins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/phillip.atkins/32/43453_2.png) [@phillip.atkins](https://discuss.hashicorp.com/u/phillip.atkins)\
**Post date:** [September 24, 2025, 1:56am UTC](https://discuss.hashicorp.com/t/help-with-winrm-timeout-issue/76545/13 "2025-09-24T01:56:33Z")

</div>

Yeah, found it, sorry, made so many adjustments, so something like this then?

custom\_data = base64encode(\<\<-EOF

```auto
<powershell>

#Configure WinRM

Write-Host "Configuring WinRM..."

New-LocalUser -Name 'packer' -Password 'PASSWORD' -FullName 'Packer User' -Description 'User for Packer build'

Add-LocalGroupMember -Group 'Administrators' -Member 'packer'

#Configure WinRM HTTP listener

winrm create winrm/config/Listener?Address=\*+Transport=HTTP "@{Hostname=\`"$env:COMPUTERNAME\`"; CertificateThumbprint=\`"$thumbprint\`"}"

#Configure WinRM service

winrm quickconfig -q

winrm set winrm/config/service '@{AllowUnencrypted="true"}'

winrm set winrm/config/service/auth '@{Basic="true"}'

 

#Configure firewall

New-NetFirewallRule -DisplayName "WinRM HTTP" -Direction Inbound -Protocol TCP -LocalPort 5985 -Action Allow

#Restart WinRM service

Restart-Service WinRM

</powershell>

EOF

```

)
