Avatar of enthuguy
enthuguyFlag for Australia

asked on 

Powershell error A positional parameter cannot be found that accepts argument

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")

Open in new window



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

Open in new window



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

thanks in advance.
Powershell* aws-cloudformatonAWS

Avatar of undefined
Last Comment
enthuguy
Avatar of oBdA
oBdA

Try it like this:
powershell.exe -Command "'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe', 'C:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config' | Set-Content -Path C:\Temp\filepath.txt"

Open in new window

Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

Thanks oBdA, trying it now
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

unfortunately, it still fails

2019-02-22 11:28:59,697 [ERROR] Command 2-addConfigFilesPath (powershell.exe powershell.exe Set-Content -Path C:\filepath.txt -Value "'C:\Program Files\Kofax\TotalAgility\Agility.Server.Web\web.config', 'C:\Program Files\Kofax\TotalAgility\Agility.Server.Web\web.config', 'C:\Program Files\Kofax\TotalAgility\CoreWorkerService\Agility.Server.Core.Executor.exe.config', 'C:\Program Files\Kofax\TotalAgility\CoreWorkerService\Agility.Server.Core.ExportService.exe.config', 'C:\Program Files\Kofax\TotalAgility\CoreWorkerService\Agility.Server.Core.WorkerService.exe', 'C:\Program Files\Kofax\TotalAgility\CoreWorkerService\Agility.Server.StreamingService.exe', 'C:\Program Files\Kofax\TotalAgility\Transformation Server\Kofax.CEBPM.CPUServer.ServiceHost.exe.config' | Set-Content -Path C:\Temp\filepath.txt") failed
2019-02-22 11:28:59,697 [DEBUG] Command 2-addConfigFilesPath output: Set-Content : A positional parameter cannot be found that accepts argument 
'Files\Kofax\TotalAgility\Agility.Server.Web\web.config'.

Open in new window



However, if I use below, file gets created but all in single line, where we expect it in multiple lines
 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')

Open in new window

Avatar of oBdA
oBdA

If you're using that as described in
https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html
then the syntax would need to be (basically the part inside the double quotes from the command above):
<powershell>
'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe', 'C:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config' | Set-Content -Path C:\Temp\filepath.txt
</powershell>

Open in new window

Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

Hi OBdA,
pls check the attached ps script (only powershell portion), execution log from the target windows server. you can see how aws converts this ps script on the target server.

you could see I replace `n with newline char in step3 after above step2 create file. I think the logic what I have in step 3 is incorrect and producing different output

pls suggest :)
cfn-powershell.yaml
cfn.zip
Avatar of oBdA
oBdA

In that yaml format, the second command would need to be
powershell.exe 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe', 'C:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config' | Set-Content -Path C:\Temp\filepath.txt

Open in new window

and the third will not be required anymore.
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

sorry, didnt work
Please check the new log :)
cfn1.zip
Avatar of oBdA
oBdA

I'd need the exact, actual, "script" file you create in order to help.
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

If I provide, I would really confuse you :)
moreover I have to strip off some code and it would it make sense to you...sorry.

have attached bit more into.

Pls note:  for testing, if I update the file manually and test rest of the scenario...they work fine.
ec2.yaml
Avatar of oBdA
oBdA

Well, you're not entering what I posted.
You added Set-Content -Path C:\filepath.txt -Value at the beginning.
That does not belong there. I posted the complete command to use, not just the value to pass to Set-Content.
The third command will be unnecessary, because the command I posted will create CRLF separated lines.
In that yaml syntax, the complete command (Set-Content appears at the end!) needs to be
powershell.exe 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe', 'C:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config' | Set-Content -Path C:\filepath.txt

Open in new window

Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

Apologies, I thought you missed it or typo ...sorry
Trying now
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

I get his error

2019-02-22 13:48:22,242 [ERROR] Command 2-addConfigFilesPath (powershell.exe 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\Agility.Server.Web\web.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.Executor.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.ExportService.exe.config', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.Core.WorkerService.exe', 'C:\Program Files\app\folder\CoreWorkerService\Agility.Server.StreamingService.exe', 'C:\Program Files\app\folder\Transformation Server\productname.CEBPM.CPUServer.ServiceHost.exe.config' | Set-Content -Path C:\filepath.txt) failed
2019-02-22 13:48:22,242 [DEBUG] Command 2-addConfigFilesPath output: 'Set-Content' is not recognized as an internal or external command,

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

Thanks, testing now
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

I think, you did it..thanks :)

I did a mistake/typo. let me retest :)
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

You are fantastic eBdA, it worked.

one of my other logic failed during step 5 (backup), Reason, file did not exist on that server.
Current line
powershell.exe foreach($line in Get-Content C:\filepath.txt){Copy-Item $line -Destination 'C:\Backup'}

Open in new window


With your Test-Path suggestion. Is this correct?
 powershell.exe foreach($line in Get-Content C:\filepath.txt) {If (Test-Path -Path $line) {Copy-Item $line -Destination 'C:\Backup'}}

Open in new window

Avatar of oBdA
oBdA

Yes, that should work.
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

yes, it worked oBdA, Thanks a lot!

You have lots of patience too :)
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo