Powershell script error

Hello All,

When I run powershell_script resource I’m getting the below error,all my Commands are appended with ‘A’ as shown below
$credential = New-Object System.Management.Automation.PSCredential($username,$securePassword);
STDERR: The term ‘New-ObjectA’ 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.

Just so we are clear, all of these are appended by chef and not within your resource block?

yes it is appended by chef when running, not me

Did you type the command directly into your cookbook, or did you copy and paste?

Copying and pasting from a powershell window inside remote desktop to a workstations is a constant pain since it often introduces hidden characters.

Depending on your text editor, try and configure it to show hidden characters. Or try retyping in the powershell command in your cookbook

1 Like

Can you please post your Chef server & client versions and also the powershell resource you are trying to run?

chef-client 11.18.12, I’m trying to run start-process

Thanks Spuder,That helped me
However I’m again getting a different error:This command cannot be run due to the error: Access is denied.
when running the below code,I guess some permission Issue with system user,please let me know how to run this
$securePassword=ConvertTo-SecureString $password -AsPlainText -Force
$credential=New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process powershell.exe -Credential $credential -NoNewWindow -ArgumentList “”

Hi @amb, the user you are using should have domain admin rights over the nodes.

when I run the above code with a local user logging into system I dont get any error, but when I run it as a system user it is prompted.