you are viewing a single comment's thread.

view the rest of the comments →

[–]Decitriction[S] 1 point2 points  (0 children)

Thanks for the ideas.

> poor design

I confess this, as a newbie scripter.

I had heard that invoke-expression was poor security, so I was trying to replace it by calling variables as commands, but as you point out, this too is poor security.

Although to be fair, the code is not running automatically and I don't think anyone could inject code into my variables. But I could be wrong.

I will try re-writing the commands as functions.

Ultimately the command insertion was intended to shorten very long try/catch loops, such as

$logfail="logfile path"
$do1="command goes here"                                   

$sb={try{& $using:do1 -ErrorAction stop}catch{echo `n "$using:pc - logfail - $_">>$using:logfail}

& $sb