AAtsushi's Blog
Security

Running InSpec by Remotely Logging in to Windows

→ 日本語版を読む

When setting up a Windows machine, you may want to connect remotely, execute PowerShell commands, and verify that the configuration is as expected.

In that case, you can connect via WinRM and use InSpec's powershell resource (note to future self).

Connect to the Windows machine via WinRM:

inspec exec foobar.rb -t winrm://<username>@<host-ip> -p '5985' --password "xxxxxx"

Use the powershell resource to execute a PowerShell command:

script = <<-EOH
    Test-NetConnection google.com -Port 443
EOH

describe powershell(script) do
    its('stdout') {should match 'TcpTestSucceeded : True'}
end

The example above verifies that a connection can be made to google.com on port 443.

WinRM requires prior configuration, so please refer to the following for guidance:

note.com

If you first need to set up an InSpec execution environment, please check the previous entry:

atsushi2022.hatenablog.com

That's all.