# Method 1
$command =
@"
ping google.com
"@
$scriptBlock = [Scriptblock]::Create($command)
Invoke-Command -ComputerName localhost -ScriptBlock $scriptBlock
# Method 2
$xVariable="K1"
$yVariable="ping"
$commandString=$yVariable+" "+$xVariable
function runCommand($command) {
if ($command[0] -eq '"') { iex "& $command" }
else { iex $command }
}
runCommand $commandString
Categories: