- This topic has 3 replies, 3 voices, and was last updated 8 months, 3 weeks ago by
December 28, 2019 at 5:44 am #195425ParticipantTopics: 1Replies: 1Points: 14Rank: Member
I am a very rookie in powershell, so pardon me if I am doing totally wrong. I have tried to understand it but its off my head,
I am trying to get this command to work to incorporate into my AWS provisioiner.
Add-Content C:\Windows\Setup\Scripts\SetupComplete.cmd “Powershell.exe -noexit -ExecutionPolicy Bypass “& ‘C:\users\administratordesktop\configure.ps1′””
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks (“&”) to pass it as part
of a string.”
If I wrap the ampersand in quotes I get
Add-Content : A positional parameter cannot be found that accepts argument ‘C:\Windows\Setup\Scripts\SetupComplete.cmd ‘.
December 28, 2019 at 6:06 am #195440ModeratorTopics: 5Replies: 237Points: 1,320Rank: Community Hero
Try this…PowerShell1Add-Content -Path C:\Windows\Setup\Scripts\SetupComplete.cmd -Value ‘powershell.exe -noexit -ExecutionPolicy Bypass “& ‘ ‘ C:\users\administratordesktop\configure.ps1’ ‘ “‘
December 28, 2019 at 4:03 pm #195479ParticipantTopics: 32Replies: 842Points: 2,687Rank: Community Hero
You’re trying to put one set of doublequotes inside another. But powershell thinks it’s two strings instead of one. You can escape the inner doublequotes with a backquote. Your trouble with “&” is that it is interpreted by cmd (run the 2nd command if the first command is true).PowerShell1Add-Content C:\Windows\Setup\Scripts\SetupComplete.cmd "Powershell.exe -noexit -ExecutionPolicy Bypass `"& 'C:\users\administratordesktop\configure.ps1'`""
But the & and quotes can be taken out.PowerShell1Add-Content C:\Windows\Setup\Scripts\SetupComplete.cmd "Powershell.exe -noexit -ExecutionPolicy Bypass C:\users\administratordesktop\configure.ps1"
I’m not sure why you need the -noexit.
December 28, 2019 at 5:40 pm #195482
- The topic ‘need help with add-content’ is closed to new replies.