Tag Archives: NoClobber

Start-Transcript

NAME
    Start-Transcript

SYNOPSIS
    Creates a record of all or part of a Windows PowerShell session in a text file.

SYNTAX
    Start-Transcript [[-Path] <string>] [-Append] [-Force] [-NoClobber] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Start-Transcript cmdlet creates a record of all or part of a Windows PowerShell session in a text file. The transcript includes all command that the user types and all output that appears on the console.

PARAMETERS
    -Append [<SwitchParameter>]
        Adds the new transcript to the end of an existing file. Use the Path parameter to specify the file.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows the cmdlet to append the transcript to an existing read-only file. When used on a read-only file, the cmdlet changes the file permission to read-write. Even using the Force parameter, the cmdlet cannot override security restrictions.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Will not overwrite (replace the contents) of an existing file. By default, if a transcript file exists in the specified path, Start-Transcript overwrites the file without warning.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies a location for the transcript file. Enter a path to a .txt file. Wildcards are not permitted.

        If you do not specify a path, Start-Transcript uses the path in the value of the $Transcript global Variable. If you have not created this Variable, Start-Transcript stores the transcripts in the $Home\My Documents directory as \PowerShell_transcript.<time-stamp>.txt files.

        If any of the directories in the path do not exist, the command fails.

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe objects to this cmdlet.

OUTPUTS
    System.String
        Start-Transcript returns a string that contains a confirmation message and the path to the output file.

NOTES

        To stop a transcript, use the Stop-Transcript cmdlet.

        To record an entire session, add the Start-Transcript command to your profile. For more information, see about_profiles.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Start-Transcript

    Description
    ———–
    This command starts a transcript in the default file location.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Start-Transcript -Path c:\transcripts\transcript0.txt -NoClobber

    Description
    ———–
    This command starts a transcript in the Transcript0.txt file in C:\transcripts. The NoClobber parameter prevents any existing files from being overwritten. If the Transcript0.txt file already exists, the command fails.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113408
    Stop-Transcript

Out-File

NAME
    Out-File

SYNOPSIS
    Sends output to a file.

SYNTAX
    Out-File [-FilePath] <string> [[-Encoding] <string>] [-Append] [-Force] [-InputObject <psobject>] [-NoClobber] [-Width <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Out-File cmdlet sends output to a file. You can use this cmdlet instead of the redirection operator (>) when you need to use its parameters.

PARAMETERS
    -Append [<SwitchParameter>]
        Adds the output to the end of an existing file, instead of replacing the file contents.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Encoding <string>
        Specifies the type of character encoding used in the file. Valid values are “Unicode”, “UTF7”, “UTF8”, “UTF32”, “ASCII”, “BigEndianUnicode”, “Default”, and “OEM”. “Unicode” is the default.

        “Default” uses the encoding of the system’s current ANSI code page.

        “OEM” uses the current original equipment manufacturer code page identifier for the operating system.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -FilePath <string>
        Specifies the path to the output file.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows the cmdlet to overwrite an existing read-only file. Even using the Force parameter, the cmdlet cannot override security restrictions.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the objects to be written to the file. Enter a Variable that contains the objects or type a command or expression that gets the objects.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Will not overwrite (replace the contents) of an existing file. By default, if a file exists in the specified path, Out-File overwrites the file without warning. If both Append and NoClobber are used, the output is appended to the existing file.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Width <int>
        Specifies the number of characters in each line of output. Any additional characters are truncated, not wrapped. If you omit this parameter, the width is determined by the characteristics of the host. The default for the Windows PowerShell console is 80 (characters).

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe any object to Out-File.

OUTPUTS
    None
        Out-File does not generate any output.

NOTES

        The Out cmdlets do not format objects; they just render them and send them to the specified display destination. If you send an unformatted object to an Out cmdlet, the cmdlet sends it to a formatting cmdlet before rendering it.

        The Out cmdlets do not have parameters for names or file paths. To send data to a cmdlet that contains the Out verb (an Out cmdlet), use a pipeline operator (|) to send the output of a Windows PowerShell command to the cmdlet. You can also store data in a Variable and use the InputObject parameter to pass the data to the cmdlet. For help, see the examples.

        Out-File sends data, but it does not emit any output objects. If you pipe the output of Out-File to Get-Member, Get-Member reports that no objects have been specified.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Process | Out-File -FilePath C:\Test1\process.txt

    Description
    ———–
    This command sends a list of processes on the computer to the Process.txt file. If the file does not exist, Out-File creates it. Because the name of the FilePath parameter is optional, you can omit it and submit the equivalent command “Get-Process | outfile C:\Test1\process.txt”.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Process | Out-File C:\Test1\process.txt -NoClobber

    Out-File : File C:\Test1\process.txt already exists and NoClobber was specified.
    At line:1 char:23
    + Get-Process | Out-File <<<< process.txt -NoClobber

    Description
    ———–
    This command also sends a list of processes to the Process.txt file, but it uses the NoClobber parameter, which prevents an existing file from being overwritten. The output shows the error message that appears when NoClobber is used with an existing file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$a = Get-Process

    C:\PS> Out-File -FilePath C:\Test1\process.txt -InputObject $a -Encoding ASCII -Width 50

    Description
    ———–
    These commands send a list of processes on the computer to the Process.txt file. The text is encoded in ASCII format so that it can be read by search programs like Findstr and Grep. By default, Out-File uses Unicode format.

    The first command gets the list of processes and stores them in the $a Variable. The second command uses the Out-File cmdlet to send the list to the Process.txt file.

    The command uses the InputObject parameter to specify that the input is in the $a Variable. It uses the Encoding parameter to convert the output to ASCII format. It uses the Width parameter to limit each line in the file to 50 characters. Because the lines of output are truncated at 50 characters, the rightmost column in the process table is omitted.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Set-Location hklm:\software

    c:\PS>Get-Acl mycompany\mykey | Out-File -FilePath c:\ps\acl.txt

    c:\PS>Get-Acl mycompany\mykey | Out-File -FilePath FileSystem::acl.txt

    Description
    ———–
    These commands show how to use the Out-File cmdlet when you are not in a FileSystem drive.

    The first command sets the current location to the HKLM:\Software Registry key.

    The second and third commands have the same effect. They use the Get-Acl cmdlet to get the security descriptor of the MyKey Registry subkey (HKLM\Software\MyCompany\MyKey). A pipeline operator passes the result to the Out-File cmdlet, which sends it to the Acl.txt file.

    Because Out-File is not supported by the Windows PowerShell Registry provider, you must specify either the file system drive name, such as “c:”, or the name of the provider followed by two colons, “FileSystem::”, in the value of the FilePath parameter. The second and third commands demonstrate these methods.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113363
    Out-String
    Out-Null
    Out-Host
    Out-Printer
    Out-Default
    Tee-Object

Export-FormatData

NAME
    Export-FormatData

SYNOPSIS
    Saves formatting data from the current session in a formatting file.

SYNTAX
    Export-FormatData [-Force] [-IncludeScriptBlock] [-InputObject <ExtendedTypeDefinition[]>] [-NoClobber] [-Path <string>] [<CommonParameters>]

DESCRIPTION
    The Export-FormatData cmdlet creates Windows PowerShell formatting files (format.ps1xml) from the formatting objects in the current session. It takes the ExtendedTypeDefinition objects that Get-FormatData returns and saves them in a file in XML format.

    Windows PowerShell uses the data in formatting files (format.ps1xml) to generate the default display of Microsoft .NET Framework objects in the session. You can view and edit the formatting files and use the Update-FormatData cmdlet to add the formatting data to a session.

    For more information about formatting files in Windows PowerShell, see about_Format.ps1xml.

PARAMETERS
    -Force [<SwitchParameter>]
        Overwrites an existing output file, even if the file has the read-only attribute.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -IncludeScriptBlock [<SwitchParameter>]
        Determines whether script blocks in the format data are exported.

        Because script blocks contain code and can be used maliciously, they are not exported by default.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <ExtendedTypeDefinition[]>
        Specifies the format data objects to be exported. Enter a Variable that contains the objects or a command that gets the objects, such as a Get-FormatData command. You can also pipe the objects from Get-FormatData to Export-FormatData.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Prevents the cmdlet from overwriting existing files. By default, Export-FormatData overwrites files without warning unless the file has the read-only attribute.

        To direct Export-FormatData to overwrite read-only files, use the Force parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies a location for the output file. Enter a path (optional) and file name with a format.ps1xml file name extension. If you omit the path, Export-FormatData creates the file in the current directory.

        If you use a file name extension other than .ps1xml, the Update-FormatData cmdlet will not recognize the file.

        If you specify an existing file, Export-FormatData overwrites the file without warning, unless the file has the read-only attribute. To overwrite a read-only file, use the Force parameter. To prevent files from being overwritten, use the NoClobber parameter.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.ExtendedTypeDefinition
        You can pipe ExtendedTypeDefinition objects from Get-FormatData to Export-FormatData.

OUTPUTS
    None
        Export-FormatData does not return any objects. It generates a file and saves it in the specified path.

NOTES

        To use any formatting file, including an exported formatting file, the execution policy for the session must allow scripts and configuration files to run. For more information, see about_execution_policies.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-FormatData -typename * | Export-FormatData -Path allformat.ps1xml -IncludeScriptBlock

    Description
    ———–
    This command exports all of the format data in the session to the AllFormat.ps1xml file.

    The command uses the Get-FormatData cmdlet to get the format data in the session. A value of * (all) for the TypeName parameter directs the cmdlet to get all of the data in the session.

    The command uses a pipeline operator (|) to send the format data from the Get-FormatData command to the Export-FormatData cmdlet, which exports the format data to the AllFormat.ps1 file.

    The Export-FormatData command uses the IncludeScriptBlock parameter to include script blocks in the format data in the file.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$f = Get-FormatData -typename helpinfoshort

    C:\PS> Export-FormatData -InputObject $f -Path c:\test\help.format.ps1xml -IncludeScriptBlock

    Description
    ———–
    These commands export the format data for the HelpInfoShort type to the Help.format.ps1xml file.

    The first command uses the Get-FormatData cmdlet to get the format data for the HelpInfoShort type, and it saves it in the $f Variable.

    The second command uses the InputObject parameter of the Export-FormatData to enter the format data saved in the $f Variable. It also uses the IncludeScriptBlock parameter to include script blocks in the output.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path process.format.ps1xml

    C:\PS> Update-FormatData -prependPath .\process.format.ps1xml

    C:\PS> Get-Process p*

    Handles NPM(K) PM(K) WS(K) VM(M) CPU(s)    Id ProcessName
    ——- —— —– —– —– ——    — ———–
        323                                     5600 powershell
        336                                     3900 powershell_ise
        138                                     4076 PresentationFontCache

    Description
    ———–
    This example shows the effect of omitting the IncludeScriptBlock parameter from an Export-FormatData command.

    The first command uses the Get-FormatData cmdlet to get the format data for the System.Diagnostics.Process object that the Get-Process cmdlet returns. The command uses a pipeline operator (|) to send the formatting data to the Export-FormatData cmdlet, which exports it to the Process.format.ps1xml file in the current directory.

    In this case, the Export-FormatData command does not use the IncludeScriptBlock parameter.

    The second command uses the Update-FormatData cmdlet to add the Process.format.ps1xml file to the current session. The command uses the PrependPath parameter to ensure that the formatting data for process objects in the Process.format.ps1xml file is found before the standard formatting data for process objects.

    The third command shows the effects of this change. The command uses the Get-Process cmdlet to get processes that have names that begin with “P”. The output shows that property values that are calculated by using script blocks are missing from the display.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=144302
    Get-FormatData
    Update-FormatData

Export-Clixml

NAME
    Export-Clixml

SYNOPSIS
    Creates an XML-based representation of an object or objects and stores it in a file.

SYNTAX
    Export-Clixml [-Path] <string> -InputObject <psobject> [-Depth <int>] [-Encoding <string>] [-Force] [-NoClobber] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Export-Clixml cmdlet creates an XML-based representation of an object or objects and stores it in a file. You can then use the Import-Clixml cmdlet to re-create the saved object based on the contents of that file.

    This cmdlet is similar to ConvertTo-Xml, except that Export-Clixml stores the resulting XML in a file. ConvertTo-Xml returns the XML, so you can continue to process it in Windows PowerShell.

PARAMETERS
    -Depth <int>
        Specifies how many levels of contained objects are included in the XML representation. The default value is 2.

        The default value can be overridden for the object type in the Types.ps1xml files. For more information, see about_types.ps1xml.

        Required?                    false
        Position?                    named
        Default value                2
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Encoding <string>
        Specifies the type of encoding for the target file. Valid values are ASCII, UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, Default, and OEM. UTF8 is the default.

        Required?                    false
        Position?                    named
        Default value                UTF8
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Causes the cmdlet to clear the read-only attribute of the output file if necessary. The cmdlet will attempt to reset the read-only attribute when the command completes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the object to be converted. Enter a Variable that contains the objects, or type a command or expression that gets the objects. You can also pipe objects to Export-Clixml.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Ensures that the cmdlet does not overwrite the contents of an existing file. By default, if a file exists in the specified path, Export-Clixml overwrites the file without warning.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies the path to the file where the XML representation of the object will be stored.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe any object to Export-Clixml.

OUTPUTS
    System.IO.FileInfo
        Export-Clixml creates a file that contains the XML.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>”This is a test” | Export-Clixml sample.xml

    Description
    ———–
    This command creates an XML file that stores a representation of the string, “This is a test”.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Acl C:\test.txt | Export-Clixml -Path fileacl.xml

    C:\PS> $fileacl = Import-Clixml fileacl.xml

    Description
    ———–
    This example shows how to export an object to an XML file and then create an object by importing the XML from the file.

    The first command uses the Get-Acl cmdlet to get the security descriptor of the Test.txt file. It uses a pipeline operator to pass the security descriptor to Export-Clixml, which stores an XML-based representation of the object in a file named FileACL.xml.

    The second command uses the Import-Clixml cmdlet to create an object from the XML in the FileACL.xml file. Then, it saves the object in the $FileAcl Variable.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113297
    Import-Clixml
    ConvertTo-Xml
    Export-Csv
    ConvertTo-Html

Export-Console

NAME
    Export-Console

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>]

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.

PARAMETERS
    -Force [<SwitchParameter>]
        Overwrites the data in a console file without warning, even if the file has the read-only attribute. The read-only attribute is changed and is not reset when the command completes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Will not overwrite (replace the contents of) an existing console file. By default, if a file exists in the specified path, Export-Console overwrites the file without warning.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies a path and file name for the console file (*.psc1). Enter a path (optional) and name. Wildcards are not permitted.

        If you type only a file name, Export-Console creates a file with that name and the “.psc1” file name extension in the current directory.

        This parameter is required unless you have opened Windows PowerShell with the PSConsoleFile parameter or exported a console file during the current session. It is also required when you use the NoClobber parameter to prevent the current console file from being overwritten.

        If you omit this parameter, Export-Console overwrites (replaces the content of) the console file that was used most recently in this session. The path to the most recently used console file is stored in the value of the $ConsoleFileName automatic Variable. For more information, see about_Automatic_Variables.

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe a path string to Export-Console.

OUTPUTS
    System.IO.FileInfo
        Export-Console creates a file that contains the exported Aliases.

NOTES

        When a console file (.psc1) is used to start the session, the name of the console file is automatically stored in the $ConsoleFileName automatic Variable. The value of $ConsoleFileName is updated when you use the Path parameter of Export-Console to specify a new console file. When no console file is used, $ConsoleFileName has no value ($null).

        To use a Windows PowerShell console file in a new session, use the following syntax to start Windows PowerShell:
        “powershell.exe -PsConsoleFile <ConsoleFile>.psc1”.

        You can also save Windows PowerShell snap-ins for future sessions by adding an Add-PSSnapin command to your Windows PowerShell profile. For more information, see about_profiles.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Export-Console -Path $pshome\Consoles\ConsoleS1.psc1

    Description
    ———–
    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 ————————–

    C:\PS>Export-Console

    Description
    ———–
    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 ————————–

    C:\PS>Add-PSSnapin NewPSSnapin

    C:\PS> Export-Console -Path NewPSSnapinConsole.psc1

    C:\PS> powershell.exe -PsConsoleFile NewPsSnapinConsole.psc1

    Description
    ———–
    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 ————————–

    C:\PS>Export-Console -Path Console01

    C:\PS> notepad console01.psc1

    <?xml version=”1.0″ encoding=”utf-8″?>
    <PSConsoleFile ConsoleSchemaVersion=”1.0″>
     <PSVersion>2.0</PSVersion>
     <PSSnapIns>
        <PSSnapIn Name=”NewPSSnapin” />
     </PSSnapIns>
    </PSConsoleFile>

    Description
    ———–
    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 ————————–

    C:\PS>powershell.exe -PSConsoleFile Console01.psc1

    C:\PS> Add-PSSnapin MySnapin

    C:\PS> Export-Console NewConsole.psc1

    C:\PS> $consolefilename

    C:\PS> Add-PSSnapin SnapIn03

    C:\PS> Export-Console

    Description
    ———–
    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.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113298
    Add-PSSnapin
    Get-PSSnapin
    Remove-PSSnapin

Export-Csv

NAME
    Export-Csv

SYNOPSIS
    Converts Microsoft .NET Framework objects into a series of comma-separated value (CSV) Variable-length strings and saves the strings in a CSV file.

SYNTAX
    Export-Csv [[-Delimiter] <char>] [-Path] <string> -InputObject <psobject> [-Encoding <string>] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf] [<CommonParameters>]

    Export-Csv [-UseCulture] [-Path] <string> -InputObject <psobject> [-Encoding <string>] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Export-Csv cmdlet creates a CSV Variable-length file that represents the objects that you submit.
    You can then use the Import-Csv cmdlet to re-create objects from the CSV strings in the files. The resulting objects are CSV versions of the original objects that consist of string representations of the property values and no methods.

    You can also use the ConvertTo-Csv and ConvertFrom-Csv cmdlets to convert .NET Framework objects to CSV strings (and back). Export-Csv is the same as ConvertTo-Csv, except that it saves the CSV strings in a file.

    You can use the parameters of the Export-Csv cmdlet to specify a delimiter other than a comma or to direct Export-Csv to use the default delimiter for the current culture.

    When you submit multiple objects to Export-Csv, Export-Csv organizes the file based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is null, as represented by two consecutive commas. If the remaining objects have additional properties, those property values are not included in the file.

    For more information, see Export-Csv, and see the Notes section.

PARAMETERS
    -Delimiter <char>
        Specifies a delimiter to separate the property values. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in quotation marks.

        Required?                    false
        Position?                    2
        Default value                , (comma)
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Encoding <string>
        Specifies the encoding for the exported CSV file. Valid values are Unicode, UTF7, UTF8, ASCII, UTF32, BigEndianUnicode, Default, and OEM. The default is ASCII.

        Required?                    false
        Position?                    named
        Default value                ASCII
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Overwrites the file specified in path without prompting.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the objects to export as CSV strings. Enter a Variable that contains the objects or type a command or expression that gets the objects. You can also pipe objects to Export-Csv.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Do not overwrite (replace the contents) of an existing file. By default, if a file exists in the specified path, Export-Csv overwrites the file without warning.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -NoTypeInformation [<SwitchParameter>]
        Omits the type information from the CSV file. By default, the first line of the CSV file contains “#TYPE ” followed by the fully-qualified name of the type of the .NET Framework object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies the path to the CSV output file. The parameter is required.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -UseCulture [<SwitchParameter>]
        Use the list separator for the current culture as the item delimiter. The default is a comma (,).

        This parameter is very useful in scripts that are being distributed to users worldwide. To find the list separator for a culture, use the following command: (Get-Culture).TextInfo.ListSeparator.

        Required?                    false
        Position?                    named
        Default value                Comma
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe any .NET Framework object to Export-Csv.

OUTPUTS
    System.String
        The CSV list is sent to the file designated in the Path parameter.

NOTES

        The Export-Csv cmdlet converts the objects that you submit into a series of CSV Variable-length strings and saves them in the specified text file. You can use Export-Csv to save objects in a CSV file and then use the Import-Csv cmdlet to create objects from the text in the CSV file.

        In the CSV file, each object is represented by a comma-separated list of the property values of the object. The property values are converted to strings (by using the ToString() method of the object), so they are generally represented by the name of the property value. Export-Csv does not export the methods of the object.

        The format of an exported file is as follows:
        — The first line of the CSV file contains the string ‘#TYPE ‘ followed by the fully qualified name of the .NET Framework type of the object, such as #TYPE System.Diagnostics.Process. To suppress this line, use the NoTypeInformation parameter.

        — The next line of the CSV file represents the column headers. It contains a comma-separated list of the names of all the properties of the first object.

        — Additional lines of the file consist of comma-separated lists of the property values of each object.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Process wmiprvse | Select-Object basePriority,ID,SessionID,WorkingSet | Export-Csv -Path data.csv

    Description
    ———–
    This command selects a few properties of the wmiprvse process and exports them to a CSV format file named data.csv.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv

    C:\PS> Get-Process | Export-Csv processes.csv

    # In processes.csv

    #TYPE System.Diagnostics.Process
    __NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,…
    Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS…
    Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\…

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. Because it does not specify a delimiter, a comma (,) is used to separate the fields in the file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -Delimiter “;”

    # In processes.csv

    #TYPE System.Diagnostics.Process
    __NounName;Name;Handles;VM;WS;PM;NPM;Path;Company;CPU;FileVersion;…
    Process;powershell;626;201666560;76058624;61943808;11960;C:\WINDOWS…
    Process;powershell;257;151920640;38322176;37052416;7836;C:\WINDOWS\…

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the Delimiter parameter to specify the semicolon (;). As a result, the fields in the file are separated by semicolons.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -UseCulture

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the UseCulture parameter to direct Export-Csv to use the delimiter specified by the ListSeparator property of the current culture.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -NoTypeInformation

    C:\PS> Get-Process | Export-Csv processes.csv -NoTypeInformation

    # In processes.csv

    __NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,…
    Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS…
    Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\…

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the NoTypeInformation parameter to suppress the type information in the file.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113299
    Import-Csv
    ConvertTo-Csv
    ConvertFrom-Csv

Export-Alias

NAME
    Export-Alias

SYNOPSIS
    Exports information about currently defined Aliases to a file.

SYNTAX
    Export-Alias [-Path] <string> [[-Name] <string[]>] [-Append] [-As {Csv | Script}] [-Description <string>] [-Force] [-NoClobber] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Export-Alias cmdlet exports the Aliases in the current session to a file. If the output file does not exist, the cmdlet will create it.

    Export-Alias can export the Aliases in a particular scope or all scopes, it can generate the data in CSV format or as a series of Set-Alias commands that you can add to a session or to a Windows PowerShell profile.

PARAMETERS
    -Append [<SwitchParameter>]
        Appends the output to the specified file, rather than overwriting the existing contents of that file.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -As <ExportAliasFormat>
        Determines the output format. CSV is the default.

        Valid values are:

        — CSV: Comma-separated value (CSV) format.
        — Script: Creates a Set-Alias command for each exported Alias. If you name the output file with a .ps1 file name extension, you can run it as a script to add the Aliases to any session.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Description <string>
        Adds a description to the exported file. The description appears as a comment at the top of the file, following the header information.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Overwrites the output file, even if the read-only attribute is set on the file.

        By default, Export-Alias overwrites files without warning, unless the read-only or hidden attribute is set or the NoClobber parameter is used in the command. The NoClobber parameter takes precedence over the Force parameter when both are used in a command.

        The Force parameter cannot force Export-Alias to overwrite files with the hidden attribute.

        Required?                    false
        Position?                    named
        Default value                Does not overwrite read-only files.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string[]>
        Specifies the names of the Aliases to export. Wildcards are permitted.

        By default, Export-Alias exports all Aliases in the session or scope.

        Required?                    false
        Position?                    2
        Default value                Export all Aliases
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Prevents Export-Alias from overwriting any files, even if the Force parameter is used in the command.

        If the NoClobber parameter is omitted, Export-Alias will overwrite an existing file without warning, unless the read-only attribute is set on the file. NoClobber takes precedence over the Force parameter, which permits Export-Alias to overwrite a file with the read-only attribute.

        NoClobber does not prevent the Append parameter from adding content to an existing file.

        Required?                    false
        Position?                    named
        Default value                Overwrites read-write files.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns objects that represent the Aliases that were exported. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value                No output
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies the path to the output file. Wildcards are permitted, but the resulting path value must resolve to a single file name. This parameter is required.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Scope <string>
        Specifies the scope from which the Aliases should be exported.

        Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

        Required?                    false
        Position?                    named
        Default value                Local
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None.
        You cannot pipe objects to this cmdlet.

OUTPUTS
    None or System.Management.Automation.AliasInfo
        When you use the Passthru parameter, Export-Alias returns a System.Management.Automation.AliasInfo object that represents the Alias. Otherwise, this cmdlet does not generate any output.

NOTES

        You can only Export-Aliases to a file.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Export-Alias -Path Alias.csv

    Description
    ———–
    This command exports current Alias information to a file named Alias.csv in the current directory.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Export-Alias -Path Alias.csv -NoClobber

    Description
    ———–
    This command exports the Aliases in the current session to an Alias.csv file.

    Because the NoClobber parameter is specified, the command will fail if an Alias.csv file already exists in the current directory.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Export-Alias -Path Alias.csv -Append -Description “Appended Aliases” -Force

    Description
    ———–
    This command appends the Aliases in the current session to the Alias.csv file.

    The command uses the Description parameter to add a description to the comments at the top of the file.

    The command also uses the Force parameter to overwrite any existing Alias.csv files, even if they have the read-only attribute.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Export-Alias -Path Alias.ps1 -As script

    C:\PS> Add-Content -Path $profile -value (Get-Content Alias.ps1)

    C:\PS> $s = New-PSSession -computername Server01
    C:\PS> Invoke-Command -session $s -filepath .\alias.ps1

    Description
    ———–
    This example shows how to use the script file format that Export-Alias generates.

    The first command exports the Aliases in the session to the Alias.ps1 file. It uses the As parameter with a value of Script to generate a file that contains a Set-Alias command for each Alias.

    The second command adds the Aliases in the Alias.ps1 file to the CurrentUser-CurrentHost profile. (The path to the profile is saved in the $profile Variable.) The command uses the Get-Content cmdlet to get the Aliases from the Alias.ps1 file and the Add-Content cmdlet to add them to the profile. For more information, see about_profiles.

    The third and fourth commands add the Aliases in the Alias.ps1 file to a remote session on the Server01 computer. The third command uses the New-PSSession cmdlet to create the session. The fourth command uses the FilePath parameter of the Invoke-Command cmdlet to run the Alias.ps1 file in the new session.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113296
    Import-Alias
    Get-Alias
    New-Alias
    Set-Alias