Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 1.0 » Invoke-Expression

Invoke-Expression - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

Invoke-Expression

Description
Run a PowerShell expression

Usage
Invoke-Expression [-command] string [CommonParameters]

Options
 -command string
       A literal string (or variable that contains a string) that is a
       valid PowerShell expression.

   CommonParameters:
      -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Example(s)
Create variables named $sorting and $MyExpr and use them to store the text of an expression, then use invoke-expression to actually run the expression:

PS C:\>$sorting = "sort-object Name"
$MyExpr = "get-process | $sorting"
invoke-expression $MyExpr