ExecuteGlobal


Definition: Executes one or more specified statements in the global namespace of a script.

 

Is there a difference between Execute and ExecuteGlobal? Yes, but we decided it wasn’t all that important, at least not for now. In turn, that meant we could simply use the same example for both statements.  In the following example, the string value “get-date” is assigned to the variable $a. The Invoke-Expression Cmdlet is then used to execute $a as though the value had been typed from the command prompt:

 

$a = "get-date"
invoke-expression $a

 

When you run these two commands you’ll get back the current date and time (because the string value "get-date" will be executed as a command).