I want to execute the following script with complex arguments. For example with [securestring].
$text = "'This is a test message.'"
$ArgumentList = @( $text, $PID ) -join ", "
$cmd = { param([string]$msg, [int]$proc ); Write-Host "$msg FROM PID: $proc" }
$Command = "Invoke-Command -ScriptBlock {$cmd} -ArgumentList $ArgumentList"
Start-Process -Filepath powershell -ArgumentList "-noexit -command ( $Command )"
this script worked fine.
i`m transform this script into the new one
$text = "'This is a test message.'"
$Cred = get-credential
$ArgumentList = @( $text, $PID, $credential ) -join ", "
$cmd = { param([string]$msg, [int]$proc, $Credential ); Write-Host "$msg FROM PID: $proc, cred: $( $Credential.username )" }
$Command = "Invoke-Command -ScriptBlock {$cmd} -ArgumentList $ArgumentList"
Start-Process -Filepath powershell -ArgumentList "-noexit -command ( $Command )"
I have an error. How to pass arguments right?