Invokes a script block in a separate powershell.exe process.
Invoke-PowerShell [-Command] <ScriptBlock> [[-Args] <Object[]>] [-x86] [[-Runtime] <String>] [<CommonParameters>]
If using PowerShell v2.0, the invoked PowerShell process can run under the .NET 4.0 CLR (using v4.0
as the value to the Runtime parameter).
If using PowerShell v4.0, you can only run the invoked PowerShell under a v4.0
CLR. If you supply a v2.0
as the value to the Runtime
parameter, and you're running PowerShell v3.0, you'll get an error.
This function launches a PowerShell process that matches the architecture of the operating system. On 64-bit operating systems, you can run under 32-bit PowerShell by specifying the x86
switch). If this function runs under a 32-bit version of PowerShell without the x86
switch, you'll get an error.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Command | ScriptBlock | The command to run. | true | false | |
Args | Object[] | Any arguments to pass to the command. | false | false | |
x86 | SwitchParameter | Run the x86 (32-bit) version of PowerShell. | false | false | |
Runtime | String | The CLR to use. Must be one of v2.0 or v4.0. Default is the current PowerShell runtime. | false | false |
Invoke-PowerShell -Command { $PSVersionTable }
Runs a separate PowerShell process which matches the architecture of the operating system, returning the $PSVersionTable from that process. This will fail under 32-bit PowerShell on a 64-bit operating system.
Invoke-PowerShell -Command { $PSVersionTable } -x86
Runs a 32-bit PowerShell process, return the $PSVersionTable from that process.
Invoke-PowerShell -Command { $PSVersionTable } -Runtime v4.0
Runs a separate PowerShell process under the v4.0 .NET CLR, returning the $PSVersionTable from that process. Should return a CLRVersion of 4.0
.