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
EOH

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" ----

STDOUT:

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 

tion

+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio 

n,chef-script20181119-16424-gcp0rd.ps1

---- 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,
Praveen

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

Rich

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

Regards,
Praveen