PowerShell Logo Small

Export-Console



This is the built-in help made by Microsoft for the command 'Export-Console', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Exports the names of snap-ins in the current session to a console file.

SYNTAX


Export-Console [[-Path] [<String>]] [-Force] [-NoClobber] [-Confirm] [-WhatIf] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Export-Console cmdlet exports the names of the Windows PowerShell snap-ins in the current session to a Windows PowerShell console file (.psc1). You can use this cmdlet
to save the snap-ins for use in future sessions.


To add the snap-ins in the .psc1 console file to a session, start Windows PowerShell (Powershell.exe) at the command line by using Cmd.exe or another Windows PowerShell
session, and then use the PSConsoleFile parameter of Powershell.exe to specify the console file.


For more information about Windows PowerShell snap-ins, see about_PSSnapins.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=289580
Add-PSSnapin
Get-PSSnapin
Remove-PSSnapin

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>export-console -path $pshome\Consoles\ConsoleS1.psc1



This command exports the names of Windows PowerShell snap-ins in the current session to the ConsoleS1.psc1 file in the Consoles subdirectory of the Windows PowerShell
installation directory, $pshome.










-------------------------- EXAMPLE 2 --------------------------

PS C:\>export-console



This command exports the names of Windows PowerShell snap-ins from current session to the Windows PowerShell console file that was most recently used in the current session.
It overwrites the previous file contents.

If you have not exported a console file during the current session, you are prompted for permission to continue and then prompted for a file name.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>add-pssnapin NewPSSnapin
PS C:\>export-console -path NewPSSnapinConsole.psc1
PS C:\>powershell.exe -PsConsoleFile NewPsSnapinConsole.psc1



These commands add the NewPSSnapin Windows PowerShell snap-in to the current session, export the names of Windows PowerShell snap-ins in the current session to a console
file, and then start a Windows PowerShell session with the console file.

The first command uses the Add-PSSnapin cmdlet to add the NewPSSnapin snap-in to the current session. You can only add Windows PowerShell snap-ins that are registered on
your system.

The second command exports the Windows PowerShell snap-in names to the NewPSSnapinConsole.psc1 file.

The third command starts Windows PowerShell with the NewPSSnapinConsole.psc1 file. Because the console file includes the Windows PowerShell snap-in name, the cmdlets and
providers in the snap-in are available in the current session.










-------------------------- EXAMPLE 4 --------------------------

PS C:\>export-console -path Console01
PS C:\>notepad console01.psc1
<?xml version="1.0" encoding="utf-8"?>
<PSConsoleFile ConsoleSchemaVersion="1.0">
<PSVersion>2.0</PSVersion>
<PSSnapIns>
<PSSnapIn Name="NewPSSnapin" />
</PSSnapIns>
</PSConsoleFile>



This command exports the names of the Windows PowerShell snap-ins in the current session to the Console01.psc1 file in the current directory.

The second command displays the contents of the Console01.psc1 file in Notepad.










-------------------------- EXAMPLE 5 --------------------------

PS C:\>powershell.exe -PSConsoleFile Console01.psc1
PS C:\>add-pssnapin MySnapin
PS C:\>export-console NewConsole.psc1
PS C:\>$consolefilename
PS C:\>add-pssnapin SnapIn03
PS C:\>export-console



This example shows how to use the $ConsoleFileName automatic variable to determine the console file that will be updated if you use Export-Console without a Path parameter
value.

The first command uses the PSConsoleFile parameter of PowerShell.exe to open Windows PowerShell with the Console01.psc1 file.

The second command uses the Add-PSSnapin cmdlet to add the MySnapin Windows PowerShell snap-in to the current session.

The third command uses the Export-Console cmdlet to export the names of all the Windows PowerShell snap-ins in the session to the NewConsole.psc1 file.

The fourth command uses the $ConsoleFileName parameter to display the most recently used console file. The sample output shows that NewConsole.ps1 is the most recently used
file.

The fifth command adds SnapIn03 to the current console.

The sixth command uses the ExportConsole cmdlet without a Path parameter. This command exports the names of all the Windows PowerShell snap-ins in the current session to the
most recently used file, NewConsole.psc1.