Skip to main content

Configuring WinRM Communication

1. Enabling WinRM

Setting Description Value
winrm_enable Enables WinRM service on the guest machine true
winrm_username Username for WinRM authentication vagrant
winrm_password Password for WinRM authentication vagrant

Example: Vagrantfile configuration for WinRM

Vagrant.configure("2") do |config|
  config.vm.box = "windows/2019"
  config.winrm.enable = true
  config.winrm.username = "vagrant"
  config.winrm.password = "vagrant"
end

2. Setting WinRM Username (config.winrm.username)

Configuration Option Value Type Description Default
config.winrm.username String Username to use for WinRM authentication. vagrant

Example: Setting WinRM Username

vagrantfile_content = <<~EOF
Vagrant.configure("2") do |config|
  config.vm.box = "my-windows-box"
  config.winrm.username = "administrator"
end
EOF
Note: The WinRM username must match the account configured on the Windows guest for remote access.

3. Setting WinRM Password (config.winrm.password)

Property Value Description
config.winrm.password "vagrant" Password used for WinRM authentication

Example: Setting WinRM Password

Vagrant.configure("2") do |config|
  config.vm.box = "windows/2019"
  config.winrm.password = "MySecurePassword123!"
end

4. Configuring WinRM Port (config.winrm.port)

Option Values Description
config.winrm.port 5985 Port number for WinRM communication. Default is 5985 for HTTP and 5986 for HTTPS.

Example: Setting WinRM Port in Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "my-windows-box"
  config.winrm.port = 5986
end

5. Setting Host (config.winrm.host)

Property Value Description
config.winrm.host localhost Specifies the hostname or IP address of the WinRM host to connect to.

Example: Setting WinRM Host

Vagrant.configure("2") do |config|
  config.winrm.host = "192.168.1.100"
end

6. Using HTTPS Transport

Property Value Description
winrm.transport https Specifies the transport protocol for WinRM communication. Must be set to https to enable secure HTTPS transport.
winrm.ssl.certificate.path /path/to/certificate.pfx Path to the certificate file used for HTTPS transport. Required when winrm.transport is set to https.
winrm.ssl.certificate.password password123 Password for the certificate file. Used to decrypt the PFX certificate.

Example: Configuring WinRM with HTTPS Transport

Vagrant.configure("2") do |config|
  config.vm.box = "windows/2019"

  # Enable WinRM over HTTPS
  config.winrm.transport = "https"
  config.winrm.ssl.certificate.path = "/path/to/certificate.pfx"
  config.winrm.ssl.certificate.password = "password123"

  # Optional: Set custom port
  config.winrm.port = 5986
end
Note: Ensure that the certificate is trusted by the client machines or configure trust accordingly to avoid SSL handshake errors.

7. Setting SSL Verification (config.winrm.ssl_peer_verification)

Property Values Description
config.winrm.ssl_peer_verification true | false Enables or disables SSL peer verification for WinRM connections.

Example: Disable SSL Verification

Vagrant.configure("2") do |config|
  config.vm.box = "my-windows-box"
  config.winrm.ssl_peer_verification = false
end
Note: Disabling SSL peer verification can expose the system to man-in-the-middle attacks. Only disable it in secure, isolated environments.

8. Configuring Timeouts (config.winrm.timeout)

Property Values Description
config.winrm.timeout 300 Timeout in seconds for WinRM operations. Default is 300 seconds (5 minutes).

Example: Setting WinRM Timeout

Vagrant.configure("2") do |config|
  config.winrm.timeout = 600
end

9. Setting Execution Time Limit

Option Values Notes
config.winrm.execution_timeout 300 Maximum time (in seconds) for WinRM operations to complete

Example: Setting Execution Timeout

Vagrant.configure("2") do |config|
  config.winrm.execution_timeout = 600
end
Note: The default execution timeout is 300 seconds (5 minutes). Adjust this value based on the expected duration of WinRM operations in your environment.

10. Using Basic Authentication

Property Value Description
config.winrm.basic_auth true Enables basic authentication for WinRM communication
config.winrm.username "vagrant" Username for WinRM authentication
config.winrm.password "vagrant" Password for WinRM authentication

Example: Basic Authentication Configuration

Vagrant.configure("2") do |config|
  config.vm.box = "windows/2019"
  config.winrm.basic_auth = true
  config.winrm.username = "vagrant"
  config.winrm.password = "vagrant"
end
Note: Basic authentication is less secure than certificate-based authentication and should only be used in development environments.

Was this article helpful?