I am creating an EC2 instance on AWS using Cloudformation template. As part of that template i am invoking a powershell script which performs the below steps (the script performs other tasks as well, but the below lines cause the error)
$MyFolder = "C:\installers\temp\Database"
$MyRHFolder = $MyFolder + "\Roundhouse"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
Write-Host "Secure password generated"
$cred = New-Object System.Management.Automation.PSCredential $Username, $securePassword
Start-Process cmd -ArgumentList "/c RoundHouseInstall.cmd" -WorkingDirectory $MyRHFolder -Credential $cred -Wait
This fails everytime when it is invoked as part of the Cloudformation stack creation. There are strangely no errors thrown or any other output in the log. The RoundHouseInstall.cmd simply does not get invoked. However, if I manually log in to the EC2 and invoke the same script it works. Also when I removed the -Credential parameter from the Start-Process command, the script worked fine even from Cloudformation, which means there is something going wrong with the credential parameter.
I need to run the script using the particular credential only otherwise the RoundHouseInstall.cmd will fail. I am out of my depth to understand why this fails and also what to try to make it work. Any assistance is appreciated.