0

i have a Problem with a new Script i am working on. This Script includes a Command where i want to execute another Programm with arguments, supportet by this Programm. At first i will get input from the PowerShell script and save this to variables, than put those variables into the argumentslist of the start process, to get it pass through the Programm. But this doesnt work as i wanted. I always see that the Programm wrotes a log in where it wrotes the variable as Name not what is inside the variable. I tried different ways but it doesnt want to work. This is the Code with some test variables:

 $goal = "dlr-1-ws240"
 $newdate = (Get-Date).AddDays(7) | Get-Date -Format "yyyy-MM-dd-12-00-00"
 $adminurl = "w10_lgrm.admin_" + $goal + "_b"
 $newmember = $env:USERNAME + ":" + $newdate
 $argulist = "-o AddMembers -service $adminurl -members $newmember"

 Start-Process "C:\Cometo V.2.5\Bin\CometClient.exe" -Argumentlist {-o AddMembers -service $adminurl -members $newmember /log}

It always detecs $newmember as the Name "$newmember" and not what its inside.

I am thankfull for every help. Thanks

Flighty
  • 13
  • 3
  • 1
    That's not how `ArgumentList` works. See the [docs](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.1#example-7--specifying-arguments-to-the-process) on a proper example. You're now passing a scriptblock `{ }` which gets translated to a string. – Jeroen Mostert Nov 18 '20 at 12:21
  • Very big thanks, i didnt saw this "little" Mistake but it really fixes everything. – Flighty Nov 18 '20 at 13:31

1 Answers1

0
&{
    param(
        [int]$packageCount,
        [string]$hostName
    )

Start-Process "ping.exe" -ArgumentList "$hostName -n $packageCount"
} -packageCount 10  -hostName "google.com"