0

I need to run PowerShell script that is working fine when using PowerShell ISE/Shell however I need to run this same command using dos commandline and then It's not working as expected.

PowerShell script/command Get-FalconUninstallToken -Id <AgentID> -PipelineVariable "<ClientID>,<ClientSecret>" | select uninstall_token | Format-Table -HideTableHeaders -OutVariable MaintToken Output: 12345567788

If I try the same using commandline I keep getting prompted for ClientID, ClientSecret powershell.exe -command Get-FalconUninstallToken -Id <clientid> -PipelineVariable "<clientID>,<clientSecret>" I've tried various other combination but so far not really succeeding any suggestions would be appreciated

I've also tried with PowerShell script instead of -command -File but same result. For some reason when trying this using Dos command prompt the ClientID,ClientSecret paramters are not accepted or I'm doing something not right.

Thx for all the help

  • The operations after `-Command` need to be a block of code, not just a list of commands and vairables. See https://stackoverflow.com/questions/40342632/how-to-use-powershell-exe-with-command-using-a-scriptblock-and-parameters – Scepticalist Apr 24 '23 at 15:13
  • Try single quotes vs double quotes. A pipeline variable is like "a", no comma (or dollar sign). – js2010 Apr 24 '23 at 15:27
  • I've tried with single quotes but no luck. I'm confused why it works fine from PowerShell (Shell) and not from command prompt, for some reason it does not like the -PipelineVariable. – Denis Gendera Apr 24 '23 at 16:08
  • I don't think you understand what -pipelinevariable does. – js2010 Apr 24 '23 at 16:23
  • @js2010 you probably right regarding -pipelinevariable but way I see it is that when I run the script inside PowerShell it works just fine and when I'm running from commandline then it does not work correctly. So makes me think that behavior is slightly different and that's what I currently try to understand Even if modify script to the below (these are dummy values) #$args1 ="1,2" #$ClientID = "3" #Get-FalconUninstallToken -Id $ClientID -PipelineVariable $args When i run the script from PowerShell command it works just fine. WIll look furhter for a solution – Denis Gendera Apr 24 '23 at 18:25
  • The linked duplicate (accepted answer) provides detailed guidance, but the short of it is: Enclose the entire PowerShell command passed to `-Command` in `"..."`, and either use `'...'` quoting inside the PowerShell command or escape embedded `"` chars. as `\"` – mklement0 Apr 24 '23 at 20:08
  • @Scepticalist, script blocks can only be used from inside PowerShell. (From outside PowerShell, you sometimes see the anti-pattern `powershell -c "& { ... }"`, but just `powershell -c "... "` is sufficient.) – mklement0 Apr 24 '23 at 21:31
  • The pipes need to be quoted so cmd doesn't run them. You might as well drop -pipelinevariable since you don't really use it. – js2010 Apr 25 '23 at 12:35

0 Answers0