Puppet Powershell execution

asked 2016-09-19 05:23:05 -0600

Shivayogi gravatar image

updated 2016-09-23 01:34:02 -0600

I have an application which requires a local account to be required for the configuration. I have created a module inside that I have 2 folders : i. files ii.manifests

under manifests init file I have the below code:

class xyz {
exec { ' app_config':
command => ' C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -file c:\provisioning\modules\xyz\files\config1.ps1 '

Under files folder there are 2 files

i. config1.ps1

ii. app_execute.bat

Under config1.ps1 I am creating a local user :

$user = $env:COMPUTERNAME/Testing

$Credentials = New-Object -TypeName System.management.Automation.PScredential -ArgumentList $user, ("test@3456", | Convertto-securestring -ASplaintext -force)

Start-Process C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -Credential $Credentials -ArgumentList " Start-Process C:\Windows\System32\cmd.exe -file c:\provisioning\c:\provisioning\modules\xyz\files\app_execute.bat "

Under app_execute.bat

c:\puppet\app.bat -f c:\puppet\responsefile.rsp

The log file shows that the powershell file config1.ps1 got executed successfully, but the application log file is not getting generated, but when executed manually the config1.ps1 the app will get configured.

Not sure, in config1.ps1, I am using a start-process which will create a separate process using the local account.

I think the puppet is not waiting for the above config1.ps1 to be completed succesfully.

Not sure why it is coming out without executing fully, Is there any condition, as we need to execute only one file inside init, as I am initiating 2 processes.

Please advise.

edit retag flag offensive close merge delete


Have you tried adding -Wait on the Start-Process to wait for the underlying process to complete? NOTE: You may want to edit your post to make the code more readable.

maynero gravatar imagemaynero ( 2016-09-21 08:22:35 -0600 )edit

@maynero, Thanks for the update, I did add the -Wait option , but I was getting "Access denied error" when I ran the script using -Wait. I will edit the post to make it clear.

Shivayogi gravatar imageShivayogi ( 2016-09-23 00:56:33 -0600 )edit

Access denied error is probably happening on your credentials part. Also your powershell script seems wonky to me. Why do you call Start-Process twice?

maynero gravatar imagemaynero ( 2016-09-23 09:40:38 -0600 )edit

Hi @maynero, I am calling twice because, I need to run the app.bat using the local account. First Start-Process will create a powershell.exe which will run with local account and in the argument list start-process will run the batch file, with local account credentials as batch files requires ..

Shivayogi gravatar imageShivayogi ( 2016-10-11 12:51:36 -0600 )edit

a local account to run.

Shivayogi gravatar imageShivayogi ( 2016-10-11 12:51:51 -0600 )edit