Export Clixml - PowerShell


Export-Clixml exports PowerShell cmdlets and providers to a Common Language Infrastructure (CLI) assembly. This enables the cmdlets and providers to be used from non-PowerShell environments, such as C# or F#.


Export-Clixml [[-InputObject] <PSSnapInInfo>] [-Namespace <string>] [-Path <string>] [-Force] [-Confirm] [-WhatIf] [-OutVariable <string>]


Specifies the PSSnapInInfo object for the snap-in containing the cmdlets and providers to export.

Specifies the namespace for the exported cmdlets and providers. The default namespace is “PowerShell”.

Specifies the path to the file where the exported cmdlets and providers will be saved. The default path is the current directory.

Forces the export to overwrite an existing file without prompting for confirmation.

Prompts for confirmation before exporting the cmdlets and providers.

Shows what would happen if the command were run without actually exporting the cmdlets and providers.

Specifies a variable to store the exported cmdlets and providers.


Simple Example

This command exports the Get-Process cmdlet to a file named Process.clixml in the current directory:

Export-Clixml -InputObject Get-Process -Path Process.clixml

Complex Example

This command exports all cmdlets and providers from the Microsoft.PowerShell.Management snap-in to a file named Management.clixml in the C:\Exports directory:

Export-Clixml -InputObject (Get-PSSnapin -Name Microsoft.PowerShell.Management) -Path C:\Exports\Management.clixml

Common Issues

  • If the specified path is not valid or does not have write permissions, the export will fail.
  • If the specified namespace is already in use by another assembly, the export will fail.


The exported cmdlets and providers can be used from non-PowerShell environments using the System.Management.Automation namespace. For example, the following C# code uses the Get-Process cmdlet exported in the previous example:

using System.Management.Automation;

namespace CSharpExample
    class Program
        static void Main(string[] args)
            // Create a PowerShell runspace.
            using (PowerShell runspace = PowerShell.Create())
                // Add the exported assembly to the runspace.

                // Create a command to get the processes.
                PowerShellCommand command = new PowerShellCommand("Get-Process");

                // Execute the command.
                Collection<PSObject> results = runspace.Invoke(command);

                // Print the process names.
                foreach (PSObject result in results)
  • Get-PSSnapin
  • Import-Clixml
  • New-PSSnapIn
  • Remove-PSSnapin