Use-PowerCLIContext

This cmdlet initializes a PowerShell runspace with a PowerCLI execution context retrieved from another PowerShell runspace.When you use VMware PowerCLI in PowerShell runspaces you have two options.The first option is to import your connections manually, for example, a vCenter Server system connection, and pass them to the corresponding cmdlets using the Server parameter.The second option is to use the Get-PowerCLIContext () cmdlet to retrieve VMware PowerCLI execution context and then use the [Use-PowerCLIContext]()cmdlet prior to using VMware PowerCLI cmdlets in the new PowerShell runspace.

Syntax

-PowerCLIContext  <PowerCliContext>
[-SkipImportModuleChecks]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
PowerCLIContext
PowerCliContext named
  • pipeline
  • Specifies the VMware PowerCLI execution context to apply.
    optional
    SkipImportModuleChecks
    SwitchParameter named Specifies to skip checks whether the imported VMware PowerCLI modules come in the same version and from the same installation location as the source session modules.

    Output

    Examples


    Example 1

    PS C:\> Use-PowerCLIContext -PowerCLIContext $context

    Initializes the current PowerShell runspace with the $context execution context.

    Example 2

    PS C:\> $context = Get-PowerCLIContext
    PS C:\> 1..5 | ForEach-Object -Parallel {
    Use-PowerCLIContext -PowerCLIContext $using:context
    New-VM -Name "MyVM_$_" -VMHost (Get-VMHost 'MyVMHost') -MemoryMB 128 -DiskMB 256
    }

    Retrieves the current PowerCLI execution context and initializes each new PowerShell runspace created by ForEach-Object -Parallel.

    Related Commands

    Feedback

    Was this page helpful?