Ullsokk
Ullsokk

Reputation: 717

Alternative to using Invoke-expression in powershell

I am using a filewatcher script to run powershell script when a new file is created.

From the code sample I used as a blueprint, the script was run using invoke-expression, which I now understand is not a reccomended approach.

Could I without any problems just use & "filepath" instead to launch the script? Or could this complicate Global variables, nesting, brackets and quotes?

Upvotes: 0

Views: 1906

Answers (1)

Joey
Joey

Reputation: 354614

No, it doesn't complicate things. It's exactly what you should do. Invoke-Expression is rarely needed outside of golfed code.

Upvotes: 1

Related Questions