troubleshooting Question

Powershell error A positional parameter cannot be found that accepts argument

Avatar of enthuguy
enthuguyFlag for Australia asked on
PowershellAWS* aws-cloudformaton
18 Comments2 Solutions641 ViewsLast Modified:
HI Powershell Experts

trying to execute a PS script as part of AWS userdata

This is how I invoke from aws cloudformation userscript.

 2-addConfigFilesPath:
  command:
    powershell.exe (Set-Content -Path C:\filepath.txt -Value "C:\Program Files\app\folder\Agility.Server.Web\web.config`nC:\Program Files\app\folder\Agility.Server.Web\web.config`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe`nC:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config")


Error:
2019-02-22 10:44:30,799 [INFO] Waiting 60 seconds for reboot
2019-02-22 10:45:30,849 [DEBUG] Running command 2-addConfigFilesPath
2019-02-22 10:45:30,849 [DEBUG] No test for command 2-addConfigFilesPath
2019-02-22 10:45:31,256 [ERROR] Command 2-addConfigFilesPath (powershell.exe (Set-Content -Path C:\filepath.txt -Value "C:\Program Files\app\folder\Agility.Server.Web\web.config`nC:\Program Files\app\folder\Agility.Server.Web\web.config`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe`nC:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe`nC:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config")) failed
2019-02-22 10:45:31,256 [DEBUG] Command 2-addConfigFilesPath output: Set-Content : A positional parameter cannot be found that accepts argument 
'Files\app\folder\Agility.Server.Web\web.config
C:\Program'.
At line:1 char:2
+ (Set-Content -Path C:\filepath.txt -Value C:\Program Files\productname\Tota ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Content], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand


Please note: when I executed manually on the target windows server. it worked fine

thanks in advance.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros