Powershell_script resource to execute commands in windows client system


Hi All,

I would like to execute couple of commands in a windows client system. Basically I need to do following :

  1. Change the directory to C:\Windows\system32
  2. Run the command cscript.exe slmgr ### (or execute the command with full path)

The code part under powershell_script resource is :

code <<-EOH
C:\Windows\System32\slmgr.vbs /skms <####>
C:\Windows\System32\slmgr.vbs /ato

But this is not working. Can you please help me to understand the issue.

The error is as follows :

[2018-11-19T22:23:20+05:30] FATAL: Mixlib::ShellOut::ShellCommandFailed: powershell_script[KMS] (kms-server-registration::kms-server-registration line 4) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'

---- Begin output of "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "G:/TEMP/chef-script20181119-16424-gcp0rd.ps1" ----


STDERR: G:\TEMP\chef-script20181119-16424-gcp0rd.ps1 : The term 'C:WindowsSystem32' is

not recognized as the name of a cmdlet, function, script file, or operable

program. Check the spelling of the name, or if a path was included, verify

that the path is correct and try again.

+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorExcep 


+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio 


---- End output of "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "G:/TEMP/chef-script20181119-16424-gcp0rd.ps1" ----

Ran "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "G:/TEMP/chef-script20181119-16424-gcp0rd.ps1" returned 1

Any help is much appreciated.

Thanks and Regards,


You need to add double slash \ in the powershell. Ruby needs the escape characters. Anything windows best practice to add \ instead of \



Thank you Rich !! Let me try it and get back.