Tag Archives: Force

Get-Item

NAME
    Get-Item

SYNOPSIS
    Gets the item at the specified location.

SYNTAX
    Get-Item [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-UseTransaction] [<CommonParameters>]

    Get-Item [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Get-Item cmdlet gets the item at the specified location. It does not get the contents of the item at the location unless you use a wildcard character (*) to request all the contents of the item.

    The Get-Item cmdlet is used by Windows PowerShell providers to enable you to navigate through different types of data stores.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user-name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

        This parameter is not supported by any providers installed with Windows PowerShell.

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

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

        The Exclude parameter is effective only when the command includes the contents of an item, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to get items that cannot otherwise be accessed, such as hidden items. Implementation varies from provider to provider. For more information, see about_providers. 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

    -Include <string[]>
        Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

        The Include parameter is effective only when the command includes the contents of an item, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.

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

    -LiteralPath <string[]>
        Specifies a path to the item. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -Path <string[]>
        Specifies the path to an item. Get-Item gets the item at the specified location. Wildcards are permitted. This parameter is required, but the parameter name (“Path”) is optional.

        Use a dot (.) to specify the current location. Use the wildcard character (*) to specify all the items in the current location.

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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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 string that contains a path to Get-Item.

OUTPUTS
    Object
        Get-Item returns the objects that it gets. The type is determined by the type of objects in the path.

NOTES

        You can also refer to Get-Item by its built-in Alias, “gi”. For more information, see about_aliases.

        Get-Item does not have a Recurse parameter, because it gets only an item, not its contents. To get the contents of an item recursively, use Get-ChildItem.

        To navigate through the Registry, use Get-Item to get Registry keys and Get-ItemProperty to get Registry values and data. The Registry values are considered to be properties of the Registry key.

        The Get-Item cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Get-Item .

    Directory: C:\

    Mode                LastWriteTime     Length Name
    —-                ————-     —— —-
    d—-         7/26/2006 10:01 AM            ps-test

    Description
    ———–
    This command gets the current directory. The dot (.) represents the item at the current location (not its contents).

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

    C:\PS>Get-Item *

    Directory: C:\ps-test

    Mode                LastWriteTime     Length Name
    —-                ————-     —— —-
    d—-         7/26/2006 9:29 AM            Logs
    d—-         7/26/2006 9:26 AM            Recs
    -a—         7/26/2006 9:28 AM         80 date.csv
    -a—         7/26/2006 10:01 AM         30 filenoext
    -a—         7/26/2006 9:30 AM     11472 process.doc
    -a—         7/14/2006 10:47 AM         30 test.txt

    Description
    ———–
    This command gets all the items in the current directory. The wildcard character (*) represents all the contents of the current item.

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

    C:\PS>Get-Item C:\

    Description
    ———–
    This command gets the current directory of the C: drive. The object that is retrieved represents only the directory, not its contents.

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

    C:\PS>Get-Item C:\*

    Description
    ———–
    This command gets the items in the C: drive. The wildcard character (*) represents all the items in the container, not just the container.

    In Windows PowerShell, use a single asterisk (*) to get contents, instead of the traditional “*.*”. The format is interpreted literally, so “*.*” would not retrieve directories or file names without a dot.

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

    C:\PS>(Get-Item C:\Windows).LastAccessTime

    Description
    ———–
    This command gets the LastAccessTime property of the C:\Windows directory. LastAccessTime is just one property of file system directories. To see all of the properties of a directory, type “(Get-Item <directory-name>) | Get-Member“.

    ————————– EXAMPLE 6 ————————–

    C:\PS>Get-Item hklm:\software\microsoft\powershell\1\shellids\microsoft.powershell\*

    Description
    ———–
    This command shows the contents of the Microsoft.PowerShell Registry key. You can use Get-Item with the Windows PowerShell Registry provider to get Registry keys and subkeys, but you must use Get-ItemProperty to get the Registry values and data.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Item c:\Windows\* -Include *.* -Exclude w*

    Description
    ———–
    This command gets items in the Windows directory with names that include a dot (.), but do not begin with w*. This command works only when the path includes a wildcard character (*) to specify the contents of the item.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113319
    about_providers
    Clear-Item
    Copy-Item
    Invoke-Item
    Move-Item
    Set-Item
    New-Item
    Remove-Item
    Rename-Item

Get-EventSubscriber

NAME
    Get-EventSubscriber

SYNOPSIS
    Gets the event subscribers in the current session.

SYNTAX
    Get-EventSubscriber [-SubscriptionId] <int> [[-Force]] [<CommonParameters>]

    Get-EventSubscriber [[-SourceIdentifier] <string>] [[-Force]] [<CommonParameters>]

DESCRIPTION
    The Get-EventSubscriber cmdlet gets the event subscribers in the current session.

    When you subscribe to an event by using a Register event cmdlet, an event subscriber is added to your Windows PowerShell session, and the events to which you subscribed are added to your event queue whenever they are raised. To cancel an event subscription, delete the event subscriber by using the Unregister-Event cmdlet.

PARAMETERS
    -Force [<SwitchParameter>]
        Gets all event subscribers, including subscribers for events that are hidden by using the SupportEvent parameter of Register-ObjectEvent, Register-WmiEvent, and Register-EngineEvent.

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

    -SourceIdentifier <string>
        Gets only the event subscribers with the specified SourceIdentifier property value. By default, Get-EventSubscriber gets all event subscribers in the session. Wildcards are not permitted. This parameter is case-sensitive.

        Required?                    false
        Position?                    1
        Default value                All event subscribers
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -SubscriptionId <int>
        Gets only the specified subscription identifier. By default, Get-EventSubscriber gets all event subscribers in the session.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        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 input to this cmdlet.

OUTPUTS
    System.Management.Automation.PSEventSubscriber
        Get-EventSubscriber returns an object that represents each event subscriber.

NOTES

        The New-Event cmdlet, which creates a custom event, does not generate a subscriber. Therefore, the Get-EventSubscriber cmdlet will not find a subscriber object for these events. However, if you use the Register-EngineEvent cmdlet to subscribe to a custom event (in order to forward the event or to specify an action), Get-EventSubscriber will find the subscriber that Register-EngineEvent generates.

        Events, event subscriptions, and the event queue exist only in the current session. If you close the current session, the event queue is discarded and the event subscription is canceled.

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

    C:\PS>$timer = New-Object Timers.Timer

    C:\PS> $timer | Get-Member -Type Event

    C:\PS> Register-ObjectEvent -inputObject $timer -EventName Elapsed -SourceIdentifier Timer.Elapsed

    C:\PS> Get-EventSubscriber

    C:\PS> $timer = New-Object Timers.Timer

    C:\PS> $timer | Get-Member -Type Event

     TypeName: System.Timers.Timer

    Name     MemberType Definition
    —-     ———- ———-
    Disposed Event     System.EventHandler Disposed(System.Object, System.EventArgs)
    Elapsed Event     System.Timers.ElapsedEventHandler Elapsed(System.Object, System.Timers.ElapsedEventArgs)

    C:\PS> Register-ObjectEvent -InputObject $timer -EventName Elapsed -SourceIdentifier Timer.Elapsed

    C:\PS> Get-EventSubscriber

    SubscriptionId : 4
    SourceObject     : System.Timers.Timer
    EventName        : Elapsed
    SourceIdentifier : Timer.Elapsed
    Action         :
    HandlerDelegate :
    SupportEvent     : False
    ForwardEvent     : False

    Description
    ———–
    This example uses a Get-EventSubscriber command to get the event subscriber for a timer event.

    The first command uses the New-Object cmdlet to create an instance of a timer object. It saves the new timer object in the $timer Variable.

    The second command uses the Get-Member cmdlet to display the events that are available for timer objects. The command uses the Type parameter of the Get-Member cmdlet with a value of Event.

    The third command uses the Register-ObjectEvent cmdlet to register for the Elapsed event on the timer object.

    The fourth command uses the Get-EventSubscriber cmdlet to get the event subscriber for the Elapsed event.

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

    C:\PS>$timer = New-Object Timers.Timer

    C:\PS> $timer.Interval = 500

    C:\PS> Register-ObjectEvent -inputObject $timer -eventName Elapsed -SourceIdentifier Timer.Random -Action { $random = Get-Random -Min 0 -Max 100 }

    Id Name         State     HasMoreData Location Command
    — —-         —–     ———– ——– ——-
    3 Timer.Random NotStarted False                 $random = Get-Random

    C:\PS> $timer.Enabled = $true

    C:\PS> $subscriber = Get-EventSubcriber -sourceIdentifer Timer.Random

    C:\PS> ($subscriber.action).gettype().fullname
    PSEventJob

    C:\PS> $subscriber.action | Format-List -property *

    State         : Running
    Module        : __DynamicModule_6b5cbe82-d634-41d1-ae5e-ad7fe8d57fe0
    StatusMessage :
    HasMoreData : True
    Location     :
    Command     : $random = Get-Random -Min 0 -Max 100
    JobStateInfo : Running
    Finished     : System.Threading.ManualResetEvent
    InstanceId    : 88944290-133d-4b44-8752-f901bd8012e2
    Id            : 1
    Name         : Timer.Random
    ChildJobs     : {}
    …

    C:\PS> & $subscriber.action.module {$random}
    96

    C:\PS> & $subscriber.action.module {$random}
    23

    Description
    ———–
    This example shows how to use the dynamic module in the PSEventJob object in the Action property of the event subscriber.

    The first command uses the New-Object cmdlet to create a timer object. The second command sets the interval of the timer to 500 (milliseconds).

    The third command uses the Register-ObjectEvent cmdlet to register the Elapsed event of the timer object. The command includes an action that handles the event. Whenever the timer interval elapses, an event is raised and the commands in the action run. In this case, the Get-Random cmdlet generates a random number between 0 and 100 and saves it in the $random Variable. The source identifier of the event is Timer.Random.

    When you use an Action parameter in a Register-ObjectEvent command, the command returns a PSEventJob object that represents the action.

    The fourth command enables the timer.

    The fifth command uses the Get-EventSubscriber cmdlet to get the event subscriber of the Timer.Random event. It saves the event subscriber object in the $subscriber Variable.

    The sixth command shows that the Action property of the event subscriber object contains a PSEventJob object. In fact, it contains the same PSEventJob object that the Register-ObjectEvent command returned.

    The seventh command uses the Format-List cmdlet to display all of the properties of the PSEventJob object in the Action property in a list. The result reveal that the PSEventJob object has a Module property that contains a dynamic script module that implements the action.

    The remaining commands use the call operator (&) to invoke the command in the module and display the value of the $random Variable. You can use the call operator to invoke any command in a module, including commands that are not exported. In this case, the commands show the random number that is being generated when the Elapsed event occurs.

    For more information about modules, see about_modules.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135155
    Register-ObjectEvent
    Register-EngineEvent
    Register-WmiEvent
    Unregister-Event
    Get-Event
    New-Event
    Remove-Event
    Wait-Event

Get-Content

NAME
    Get-Content

SYNOPSIS
    Gets the content of the item at the specified location.

SYNTAX
    Get-Content [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

    Get-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file. It reads the content one line at a time and returns an object for each line.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

        This parameter is not supported by any providers that are installed with Windows PowerShell.

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

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

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

    -Include <string[]>
        Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -LiteralPath <string[]>
        Specifies the path to an item. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -Path <string[]>
        Specifies the path to an item. Get-Content retrieves the content of the item. Wildcards are permitted. The parameter name (“Path” or “FilePath”) is optional.

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

    -ReadCount <Int64>
        Specifies how many lines of content are sent through the pipeline at a time. The default value is 1. A value of 0 (zero) sends all of the content at one time.

        This parameter does not change the content displayed, but it does affect the time it takes to display the content. As the value of ReadCount increases, the time it takes to return the first line increases, but the total time for the operation decreases. This can make a perceptible difference in very large items.

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

    -TotalCount <Int64>
        Specifies how many lines of content are retrieved. The default is -1 (all lines).

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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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 input to Get-Content.

OUTPUTS
    Object
        Get-Content returns objects that represent the content that it gets. The object type depends on the content type.

NOTES

        You can also refer to Get-Content by its built-in Aliases, “cat”, “type” and “gc”. For more information, see about_aliases.

        The Get-Content cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Get-Content -Path C:\Chapters\chapter1.txt

    Description
    ———–
    This command displays the content of the Chapter1.txt file on the console. It uses the Path parameter to specify the name of the item. Get-Content actually passes the content down the pipeline, but because there are no other pipeline elements, the content is formatted and displayed on the console.

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

    C:\PS>Get-Content c:\Logs\Log060912.txt -TotalCount 50 | Set-Content sample.txt

    Description
    ———–
    This command gets the first 50 lines of the Log060912.txt file and stores them in the sample.txt file. The command uses the Get-Content cmdlet to get the text in the file. (The name of Path parameter, which is optional, is omitted.) The TotalCount parameter limits the retrieval to the first 50 lines. The pipeline operator (|) sends the result to Set-Content, which places it in the sample.txt file.

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

    C:\PS>(Get-Content cmdlets.txt -TotalCount 5)[-1]

    Description
    ———–
    This command gets the fifth line of the Cmdlets.txt text file. It uses the TotalCount parameter to get the first five lines and then uses array notation to get the last line (indicated by “-1”) of the resulting set.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113310
    about_providers
    Add-Content
    Set-Content
    Clear-Content

Get-ChildItem

NAME
    Get-ChildItem

SYNOPSIS
    Gets the items and child items in one or more specified locations.

SYNTAX
    Get-ChildItem [[-Path] <string[]>] [[-Filter] <string>] [-Exclude <string[]>] [-Force] [-Include <string[]>] [-Name] [-Recurse] [-UseTransaction] [<CommonParameters>]

    Get-ChildItem [-LiteralPath] <string[]> [[-Filter] <string>] [-Exclude <string[]>] [-Force] [-Include <string[]>] [-Name] [-Recurse] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers.

    A location can be a file system location, such as a directory, or a location exposed by another provider, such as a Registry hive or a Certificate store.

PARAMETERS
    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to get items that cannot otherwise not be accessed by the user, such as hidden or system files. Implementation varies from provider to provider. For more information, see about_providers. 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

    -Include <string[]>
        Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

        The Include parameter is effective only when the command includes the Recurse parameter or the path leads to the contents of a directory, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.

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

    -LiteralPath <string[]>
        Specifies a path to one or more locations. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -Name [<SwitchParameter>]
        Retrieves only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent.

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

    -Path <string[]>
        Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).

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

    -Recurse [<SwitchParameter>]
        Gets the items in the specified locations and in all child items of the locations.

        Recurse works only when the path points to a container that has child items, such as C:\Windows or C:\Windows\*, and not when it points to items that do not have child items, such as C:\Windows\*.exe.

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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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 string that contains a path to Get-ChildItem.

OUTPUTS
    Object.
        The type of object that Get-ChildItem returns is determined by the provider with which it is used.

NOTES

        You can also refer to Get-ChildItem by its built-in Aliases, “ls”, “dir”, and “gci”. For more information, see about_aliases.

        Get-ChildItem does not get hidden items by default. To get hidden items, use -Force.

        The Get-ChildItem cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Get-ChildItem

    Description
    ———–
    This command gets the child items in the current location. If the location is a file system directory, it gets the files and sub-directories in the current directory. If the item does not have child items, this command returns to the command prompt without displaying anything.

    The default display lists the mode (attributes), last write time, file size (length), and the name of the file. The valid values for mode are d (directory), a (archive), r (read-only), h (hidden), and s (system).

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

    C:\PS>Get-ChildItem . -Include *.txt -Recurse -Force

    Description
    ———–
    This command retrieves all of the .txt files in the current directory and its subdirectories. The dot (.) represents the current directory and the Include parameter specifies the file name extension. The Recurse parameter directs Windows PowerShell to retrieve objects recursively, and it indicates that the subject of the command is the specified directory and its contents. The force parameter adds hidden files to the display.

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

    C:\PS>Get-ChildItem c:\windows\logs\* -Include *.txt -Exclude A*

    Description
    ———–
    This command lists the .txt files in the Logs subdirectory, except for those whose names start with the letter A. It uses the wildcard character (*) to indicate the contents of the Logs subdirectory, not the directory container. Because the command does not include the Recurse parameter, Get-ChildItem does not include the content of directory automatically; you need to specify it.

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

    C:\PS>Get-ChildItem Registry::hklm\software

    Description
    ———–
    This command retrieves all of the Registry keys in the HKEY_LOCAL_MACHINE\SOFTWARE key in the Registry of the local computer.

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

    C:\PS>Get-ChildItem -Name

    Description
    ———–
    This command retrieves only the names of items in the current directory.

    ————————– EXAMPLE 6 ————————–

    C:\PS>Get-ChildItem cert:\. -Recurse -codesigningcert

    Description
    ———–
    This command gets all of the Certificates in the Certificate store that have code-signing authority.

    The command uses the Get-ChildItem cmdlet. The path specifies the Cert: drive exposed by the Windows PowerShell Certificate provider. The backslash (\) symbol specifies a subdirectory of the Certificate store and the dot (.) represents the current directory, which would be the root directory of the Certificate store. The Recurse parameter specifies a recursive search.

    The CodeSigningCertificate parameter is a dynamic parameter that gets only Certificates with code-signing authority. For more information, type “Get-Help Certificate“.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-ChildItem * -Include *.exe

    Description
    ———–
    This command retrieves all of the items in the current directory with a “.exe” file name extension. The wildcard character (*) represents the contents of the current directory (not the container). When using the Include parameter without the Recurse parameter, the path must point to contents, not a container.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113308
    about_providers
    Get-Item
    Get-Alias
    Get-Location
    Get-Process

Format-Wide

NAME
    Format-Wide

SYNOPSIS
    Formats objects as a wide table that displays only one property of each object.

SYNTAX
    Format-Wide [[-Property] <Object>] [-AutoSize] [-Column <int>] [-DisplayError] [-Expand <string>] [-Force] [-GroupBy <Object>] [-InputObject <psobject>] [-ShowError] [-View <string>] [<CommonParameters>]

DESCRIPTION
    The Format-Wide cmdlet formats objects as a wide table that displays only one property of each object. You can use the Property parameter to determine which property is displayed.

PARAMETERS
    -AutoSize [<SwitchParameter>]
        Adjusts the column size and number of columns based on the width of the data. By default, the column size and number are determined by the view. You cannot use the AutoSize and Column parameters in the same command.

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

    -Column <int>
        Specifies the number of columns in the display. You cannot use the AutoSize and Column parameters in the same command.

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

    -DisplayError [<SwitchParameter>]
        Displays errors at the command line.

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

    -Expand <string>
        Formats the collection object, as well as the objects in the collection. This parameter is designed to format objects that support the ICollection (System.Collections) interface. The default value is EnumOnly.

        Valid values are:
        — EnumOnly: Displays the properties of the objects in the collection.
        — CoreOnly: Displays the properties of the collection object.
        — Both: Displays the properties of the collection object and the properties of objects in the collection.

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

    -Force [<SwitchParameter>]
        Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

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

    -GroupBy <Object>
        Formats the output in groups based on a shared property or value. Enter an expression or a property of the output.

        The value of the GroupBy parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>

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

    -InputObject <psobject>
        Specifies the objects to be formatted. 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

    -Property <Object>
        Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted.

        If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name (“Property”) is optional. You cannot use the Property and View parameters in the same command.

        The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Expression <string> or <script block>
        — FormatString <string>

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

    -ShowError [<SwitchParameter>]
        Sends errors through the pipeline.

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

    -View <string>
        Specifies the name of an alternate table format or “view.” You cannot use the Property and View parameters in the same 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 Format-Wide.

OUTPUTS
    Microsoft.PowerShell.Commands.Internal.Format
        Format-Wide returns format objects that represent the table.

NOTES

        You can also refer to Format-Wide by its built-in Alias, “fw”. For more information, see about_aliases.

        The GroupBy parameter assumes that the objects are sorted. Before using Format-Custom to group the objects, use Sort-Object to sort them.

        The -View parameter lets you specify an alternate format for the table. You can use the views defined in the *.format.PS1XML files in the Windows PowerShell directory or you can create your own views in new PS1XML files and use the Update-FormatData cmdlet to include them in Windows PowerShell.

        The alternate view for the View parameter must use table format; if it does not, the command fails. If the alternate view is a list, use Format-List. If the alternate view is neither a list nor a table, use Format-Custom.

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

    C:\PS>Get-ChildItem | Format-Wide -Column 3

    Description
    ———–
    This command displays the names of files in the current directory in three columns across the screen. The Get-ChildItem cmdlet gets objects representing each file in the directory. The pipeline operator (|) passes the file objects through the pipeline to Format-Wide, which formats them for output. The Column parameter specifies the number of columns.

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

    C:\PS>Get-ChildItem HKCU:\software\microsoft | Format-Wide -Property pschildname -AutoSize

    Description
    ———–
    This command displays the names of Registry keys in the HKEY_CURRENT_USER\Software\Microsoft key. The Get-ChildItem cmdlet gets objects representing the keys. The path is specified as “HKCU:”, one of the drives exposed by the Windows PowerShell Registry provider, followed by the key path. The pipeline operator (|) passes the Registry key objects through the pipeline to Format-Wide, which formats them for output. The Property parameter specifies the name of the property, and the AutoSize parameter adjusts the columns for readability.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113304

Format-Table

NAME
    Format-Table

SYNOPSIS
    Formats the output as a table.

SYNTAX
    Format-Table [[-Property] <Object[]>] [-AutoSize] [-DisplayError] [-Expand <string>] [-Force] [-GroupBy <Object>] [-HideTableHeaders] [-InputObject <psobject>] [-ShowError] [-View <string>] [-Wrap] [<CommonParameters>]

DESCRIPTION
    The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column, but you can use the Property parameter to select the properties that you want to see.

    You can also use a hash table to add calculated properties to an object before displaying it and to specify the column headings in the table. To add a calculated property, use the Property or GroupBy parameters.

PARAMETERS
    -AutoSize [<SwitchParameter>]
        Adjusts the column size and number of columns based on the width of the data. By default, the column size and number are determined by the view.

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

    -DisplayError [<SwitchParameter>]
        Displays errors at the command line.

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

    -Expand <string>
        Formats the collection object, as well as the objects in the collection. This parameter is designed to format objects that support the ICollection (System.Collections) interface. The default value is EnumOnly.

        Valid values are:
        — EnumOnly: Displays the properties of the objects in the collection.
        — CoreOnly: Displays the properties of the collection object.
        — Both: Displays the properties of the collection object and the properties of objects in the collection.

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

    -Force [<SwitchParameter>]
        Directs the cmdlet to display all of the error information. Use with the DisplayError or ShowError parameters. By default, when an error object is written to the error or display streams, only some of the error information is displayed.

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

    -GroupBy <Object>
        Arranges sorted output in separate tables based on a property value. For example, you can use GroupBy to list services in separate tables based on their status.

        Enter an expression or a property of the output. The output must be sorted before you send it to Format-Table.

        The value of the GroupBy parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>

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

    -HideTableHeaders [<SwitchParameter>]
        Omits the column headings from the table.

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

    -InputObject <psobject>
        Specifies the objects to be formatted. 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

    -Property <Object[]>
        Specifies the object properties that appear in the display and the order in which they appear. Type one or more property names (separated by commas), or use a hash table to display a calculated property. Wildcards are permitted.

        If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name (“Property”) is optional. You cannot use the Property and View parameters in the same command.

        The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>
        — Width <int32>
        — Alignment (value can be “Left”, “Center”, or “Right”)

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

    -ShowError [<SwitchParameter>]
        Sends errors through the pipeline.

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

    -View <string>
        Specifies the name of an alternate table format or “view.” You cannot use the Property and View parameters in the same command.

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

    -Wrap [<SwitchParameter>]
        Displays text that exceeds the column width on the next line. By default, text that exceeds the column width is truncated.

        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 Format-Table.

OUTPUTS
    Microsoft.PowerShell.Commands.Internal.Format
        Format-Table returns format objects that represent the table.

NOTES

        You can also refer to Format-Table by its built-in Alias, “FT”. For more information, see about_aliases.

        The GroupBy parameter assumes that the objects are sorted. Before using Format-Custom to group the objects, use Sort-Object to sort them.

        The View parameter lets you specify an alternate format for the table. You can use the views defined in the *.format.PS1XML files in the Windows PowerShell directory or you can create your own views in new PS1XML files and use the Update-FormatData cmdlet to include them in Windows PowerShell.

        The alternate view for the View parameter must use table format; if it does not, the command fails. If the alternate view is a list, use Format-List. If the alternate view is neither a list nor a table, use Format-Custom.

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

    C:\PS>Get-PSSnapin | Format-Table -auto

    Description
    ———–
    This command formats information about Windows PowerShell snap-ins in a table. By default, they are formatted in a list. The Get-PSSnapin cmdlets gets objects representing the snap-ins. The pipeline operator (|) passes the object to the Format-Table command. Format-Table formats the objects in a table. The Autosize parameter adjusts the column widths to minimize truncation.

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

    C:\PS>Get-Process | Sort-Object -Property basepriority | Format-Table -GroupBy basepriority -Wrap

    Description
    ———–
    This command displays the processes on the computer in groups with the same base priority.

    The Get-Process cmdlet gets objects representing each process on the computer. The pipeline operator (|) passes the object to the Sort-Object cmdlet, which sorts the objects in order of their base priority.

    Another pipeline operator passes the results to the Format-Table command. The GroupBy parameter arranges the data about the processes into groups based on the value of their BasePriority property. The Wrap parameter ensures that data is not truncated.

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

    C:\PS>Get-Process | Sort-Object starttime | Format-Table -View starttime

    Description
    ———–
    This command displays information about the processes on the computer in group based on the start date of the process. It uses the Get-Process cmdlet to get objects representing the processes on the computer. The pipeline operator (|) sends the output of Get-Process to the Sort-Object cmdlet, which sorts it based on the StartTime property. Another pipeline operator sends the sorted results to Format-Table.

    The View parameter is used to select the StartTime view that is defined in the DotNetTypes.format.ps1xml formatting file for System.Diagnostics.Process objects, such as those returned by Get-Process. This view converts the StartTime of the process to a short date and then groups the processes by start date.

    The DotNetTypes.format.ps1xml formatting file also contains a Priority view for processes, and you can create your own format.ps1xml files with customized views.

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

    C:\PS>Get-Service | Format-Table -Property Name, DependentServices

    Description
    ———–
    This command displays all of the services on the computer in a table with two columns, Name and DependentServices. The command uses the Get-Service cmdlet to get all of the services on the computer. The pipeline operator (|) sends the results to the Format-Table cmdlet, which formats the output in a table. The Property parameter specifies the properties that appear in the table as columns. The name of the Property parameter is optional, so you can omit it (“Format-Table name, dependentservices”).

    Property and DependentServices are just two of the properties of service objects. To view all of the properties, type “Get-Service | Get-Member“.

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

    C:\PS>Get-Process notepad | Format-Table ProcessName, `
    @{Label=”TotalRunningTime”; Expression={(Get-Date) – $_.StartTime}}

    Description
    ———–
    This command shows how to use a calculated property in a table. The command displays a table with the process name and total running time of all Notepad processes on the local computer. The total running time is calculated by subtracting the start time of each process from the current time.

    The command uses the Get-Process cmdlet to get all processes named “Notepad” on the local computer. The pipeline operator (|) sends the results to Format-Table, which displays a table with two columns: ProcessName, a standard property of processes, and TotalRunningTime, a calculated property.

    The TotalRunningTime property is specified by a hash table with two keys, Label and Expression. The name of the property is assigned to the Label key. The calculation is assigned to the Expression key. The expression gets the StartTime property of each process object and subtracts it from the result of a Get-Date command, which gets the current date (and time).

    ————————– EXAMPLE 6 ————————–

    C:\PS>$processes = Get-WmiObject -ComputerName Server01 win32_process -filter “name=’notepad.exe'”

    C:\PS> $processes | Format-Table ProcessName, @{ Label = “Total Running Time”; `
    Expression={(Get-Date) – $_.ConvertToDateTime($_.CreationDate)}}

    Description
    ———–
    These commands are similar to the previous command, except that these commands use the Get-WmiObject cmdlet and the Win32_Process class to display information about Notepad processes on a remote computer.

    The first command uses the Get-WmiObject cmdlet to get instances of the Windows Management Instrumentation (WMI) Win32_Process class that describes all of the processes on the Server01 computer that are named Notepad.exe. The command stores the process information in the $processes Variable.

    The second command uses a pipeline operator (|) to send the process information in the $processes Variable to the Format-Table cmdlet, which displays the ProcessName of each process along with a new calculated property.

    The command assigns the name of the new calculated property, Total Running Time, to the Label key. The script block that is assigned to the Expression key calculates how long the process has been running by subtracting the creation date of the process from the current date. The Get-Date cmdlet gets the current date. The ConvertToDateTime method converts the CreationDate property of the Win32_Process object from a WMI CIM_DATETIME object to a Microsoft .NET Framework DateTime object that can be compared with the output of Get-Date. Then, the converted creation date is subtracted from the current date. The result is the value of Total Running Time.

    The backtick characters (`) are line continuation characters.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113303
    Format-List
    Format-Wide
    Format-Custom

Format-List

NAME
    Format-List

SYNOPSIS
    Formats the output as a list of properties in which each property appears on a new line.

SYNTAX
    Format-List [[-Property] <Object[]>] [-DisplayError] [-Expand <string>] [-Force] [-GroupBy <Object>] [-InputObject <psobject>] [-ShowError] [-View <string>] [<CommonParameters>]

DESCRIPTION
    The Format-List cmdlet formats the output of a command as a list of properties in which each property is displayed on a separate line. You can use Format-List to format and display all or selected properties of an object as a list (Format-List *).

    Because more space is available for each item in a list than in a table, Windows PowerShell displays more properties of the object in the list, and the property values are less likely to be truncated.

PARAMETERS
    -DisplayError [<SwitchParameter>]
        Displays errors at the command line.

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

    -Expand <string>
        Formats the collection object, as well as the objects in the collection. This parameter is designed to format objects that support the ICollection (System.Collections) interface. The default value is EnumOnly.

        Valid values are:
        — EnumOnly: Displays the properties of the objects in the collection.
        — CoreOnly: Displays the properties of the collection object.
        — Both: Displays the properties of the collection object and the properties of objects in the collection.

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

    -Force [<SwitchParameter>]
        Directs the cmdlet to display all of the error information. Use with the DisplayError or ShowError parameters. By default, when an error object is written to the error or display streams, only some of the error information is displayed.

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

    -GroupBy <Object>
        Formats the output in groups based on a shared property or value. Enter an expression or a property of the output.

        The value of the GroupBy parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>

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

    -InputObject <psobject>
        Specifies the objects to be formatted. 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

    -Property <Object[]>
        Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted.

        If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name (“Property”) is optional. You cannot use the Property and View parameters in the same command.

        The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>

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

    -ShowError [<SwitchParameter>]
        Sends errors through the pipeline.

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

    -View <string>
        Specifies the name of an alternate list format or “view.” You cannot use the Property and View parameters in the same 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 Format-List.

OUTPUTS
    Microsoft.PowerShell.Commands.Internal.Format
        Format-List returns the format objects that represent the list.

NOTES

        You can also refer to Format-List by its built-in Alias, “FL”. For more information, see about_aliases.

        The format cmdlets, such as Format-List, arrange the data to be displayed but do not display it. The data is displayed by the output features of Windows PowerShell and by the cmdlets that contain the Out verb (the Out cmdlets), such as Out-Host, Out-File, and Out-Printer.

        If you do not use a format cmdlet, Windows PowerShell applies that default format for each object that it displays.

        The GroupBy parameter assumes that the objects are sorted. Before using Format-Custom to group the objects, use Sort-Object to sort them.

        The View parameter lets you specify an alternate format for the table. You can use the views defined in the *.format.PS1XML files in the Windows PowerShell directory, or you can create your own views in new PS1XML files and use the Update-FormatData cmdlet to include them in Windows PowerShell.

        The alternate view for the View parameter must use the list format; if not, the command fails. If the alternate view is a table, use Format-Table. If the alternate view is neither a list nor a table, use Format-Custom.

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

    C:\PS>Get-Service | Format-List

    Description
    ———–
    This command formats information about services on the computer as a list. By default, the services are formatted as a table. The Get-Service cmdlet gets objects representing the services on the computer. The pipeline operator (|) passes the results through the pipeline to Format-List. Then, the Format-List command formats the service information in a list and sends it to the default output cmdlet for display.

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

    C:\PS>$a = Get-ChildItem $pshome\*.ps1xml

    Description
    ———–
    These commands display information about the PS1XML files in the Windows PowerShell directory as a list. The first command gets the objects representing the files and stores them in the $a Variable. The second command uses Format-List to format information about objects stored in $a. This command uses the InputObject parameter to pass the Variable to Format-List, which then sends the formatted output to the default output cmdlet for display.

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

    C:\PS>Get-Process | Format-List -Property name, basepriority, priorityclass

    Description
    ———–
    This command displays the name, base priority, and priority class of each process on the computer. It uses the Get-Process cmdlet to get an object representing each process. The pipeline operator (|) passes the process objects through the pipeline to Format-List. Format-List formats the processes as a list of the specified properties. The “Property” parameter name is optional, so you can omit it.

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

    C:\PS>Get-Process winlogon | Format-List -Property *

    Description
    ———–
    This command displays all of the properties of the Winlogon process. It uses the Get-Process cmdlet to get an object representing the Winlogon process. The pipeline operator (|) passes the Winlogon process object through the pipeline to Format-List. The command uses the Property parameter to specify the properties and the * to indicate all properties. Because the name of the Property parameter is optional, you can omit it and type the command as: “Format-List *”. Format-List automatically sends the results to the default output cmdlet for display.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113302

Format-Custom

NAME
    Format-Custom

SYNOPSIS
    Uses a customized view to format the output.

SYNTAX
    Format-Custom [[-Property] <Object[]>] [-Depth <int>] [-DisplayError] [-Expand <string>] [-Force] [-GroupBy <Object>] [-InputObject <psobject>] [-ShowError] [-View <string>] [<CommonParameters>]

DESCRIPTION
    The Format-Custom cmdlet formats the output of a command as defined in an alternate view. Format-Custom is designed to display views that are not just tables or just lists. You can use the views defined in the *format.PS1XML files in the Windows PowerShell directory, or you can create your own views in new PS1XML files and use the Update-FormatData cmdlet to add them to Windows PowerShell.

PARAMETERS
    -Depth <int>
        Specifies the number of columns in the display.

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

    -DisplayError [<SwitchParameter>]
        Displays errors at the command line.

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

    -Expand <string>
        Formats the collection object, as well as the objects in the collection. This parameter is designed to format objects that support the ICollection (System.Collections) interface. The default value is EnumOnly.

        Valid values are:
        — EnumOnly: Displays the properties of the objects in the collection.
        — CoreOnly: Displays the properties of the collection object.
        — Both: Displays the properties of the collection object and the properties of objects in the collection.

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

    -Force [<SwitchParameter>]
        Directs the cmdlet to display all of the error information. Use with the DisplayError or ShowError parameters. By default, when an error object is written to the error or display streams, only some of the error information is displayed.

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

    -GroupBy <Object>
        Formats the output in groups based on a shared property or value. Enter an expression or a property of the output.

        The value of the GroupBy parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>

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

    -InputObject <psobject>
        Specifies the objects to be formatted. 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

    -Property <Object[]>
        Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted.

        If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name (“Property”) is optional. You cannot use the Property and View parameters in the same command.

        The value of the Property parameter can be a new calculated property. To create a calculated property, use a hash table. Valid keys are:

        — Expression <string> or <script block>
        — Depth <int32>

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

    -ShowError [<SwitchParameter>]
        Sends errors through the pipeline.

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

    -View <string>
        Specifies the name of an alternate format or “view.” If you omit this parameter, Format-Custom uses a default custom view. You cannot use the Property and View parameters in the same 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 Format-Custom

OUTPUTS
    Microsoft.PowerShell.Commands.Internal.Format
        Format-Custom returns the format objects that represent the display.

NOTES

        Format-Custom is designed to display views that are not just tables or just lists. To display an alternate table view, use Format-Table. To display an alternate list view, use Format-List.

        You can also refer to Format-Custom by its built-in Alias, “fc”. For more information, see about_aliases.

        The GroupBy parameter assumes that the objects are sorted. Before using Format-Custom to group the objects, use Sort-Object to sort them.

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

    C:\PS>Get-Command Start-Transcript | Format-Custom -View MyView

    Description
    ———–
    This command formats information about the Start-Transcript cmdlet in the format defined by the MyView view, a custom view created by the user. To run this command successfully, you must first create a new PS1XML file, define the MyView view, and then use the Update-FormatData command to add the PS1XML file to Windows PowerShell.

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

    C:\PS>Get-Process Winlogon | Format-Custom

    Description
    ———–
    This command formats information about the Winlogon process in an alternate customized view. Because the command does not use the View parameter, Format-Custom uses a default custom view to format the data.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113301

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

NAME
    Export-PSSession

SYNOPSIS
    Imports commands from another session and saves them in a Windows PowerShell module.

SYNTAX
    Export-PSSession [-Session] <PSSession> [-OutputModule] <string> [[-CommandName] <string[]>] [[-FormatTypeName] <string[]>] [-AllowClobber] [-ArgumentList <Object[]>] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | All}] [-Encoding <string>] [-Force] [-Module <string[]>] [<CommonParameters>]

DESCRIPTION
    The Export-PSSession cmdlet gets cmdlets, Functions, Aliases, and other command types from another PSSession on a local or remote computer and saves them in a Windows PowerShell module. To add the commands from the module to the current session, use the Import-Module cmdlet.

    Unlike Import-PSSession, which imports commands from another PSSession into the current session, Export-PSSession saves the commands in a module. The commands are not imported into the current session.

    To export commands, first use the New-PSSession cmdlet to create a PSSession that has the commands that you want to export. Then use the Export-PSSession cmdlet to export the commands. By default, Export-PSSession exports all commands, except for commands that exist in the current session, but you can use the CommandName parameters to specify the commands to export.

    The Export-PSSession cmdlet uses the implicit remoting feature of Windows PowerShell. When you import commands into the current session, they run implicitly in the original session or in a similar session on the originating computer.

PARAMETERS
    -AllowClobber [<SwitchParameter>]
        Exports the specified commands, even if they have the same names as commands in the current session.

        If you import a command with the same name as a command in the current session, the imported command hides or replaces the original commands. For more information, see about_command_precedence.

        Export-PSSession does not import commands that have the same names as commands in the current session. The default behavior is designed to prevent command name conflicts.

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

    -ArgumentList <Object[]>
        Exports the variant of the command that results from using the specified arguments (parameter values).

        For example, to export the variant of the Get-Item command in the Certificate (Cert:) drive in the PSSession in $s, type “Export-PSSession -Session $s -command Get-Item -ArgumentList cert:”.

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

    -CommandName <string[]>
        Exports only the commands with the specified names or name patterns. Wildcards are permitted. Use “CommandName” or its Alias, “Name”.

        By default, Export-PSSession exports all commands from the PSSession except for commands that have the same names as commands in the current session. This prevents imported commands from hiding or replacing commands in the current session. To export all commands, even those that hide or replace other commands, use the AllowClobber parameter.

        If you use the CommandName parameter, the formatting files for the commands are not exported unless you use the FormatTypeName parameter. Similarly, if you use the FormatTypeName parameter, no commands are exported unless you use the CommandName parameter.

        Required?                    false
        Position?                    3
        Default value                All commands in the session.
        Accept pipeline input?     false
        Accept wildcard characters? true

    -CommandType <CommandTypes>
        Exports only the specified types of command objects. Use “CommandType” or its Alias, “Type”.

        Valid values are:
        — Alias: All Windows PowerShell Aliases in the current session.
        — All: All command types. It is the equivalent of “Get-Command *”.
        — Application: All files other than Windows PowerShell files in paths listed in the Path Environment Variable ($env:path), including .txt, .exe, and .dll files.
        — Cmdlet: The cmdlets in the current session. “Cmdlet” is the default.
        — ExternalScript: All .ps1 files in the paths listed in the Path Environment Variable ($env:path).
        — Filter and Function: All Windows PowerShell Functions.
        — Script: Script blocks in the current session.

        Required?                    false
        Position?                    named
        Default value                All commands in the session.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Encoding <string>
        Specifies the encoding for the output files. Valid values are “Unicode”, “UTF7”, “UTF8”, “ASCII”, “UTF32”, “BigEndianUnicode”, “Default”, and “OEM”. The default is “UTF-8”.

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

    -Force [<SwitchParameter>]
        Overwrites one or more existing output files, even if the file has the read-only attribute.

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

    -FormatTypeName <string[]>
        Exports formatting instructions only for the specified Microsoft .NET Framework types. Enter the type names. By default, Export-PSSession exports formatting instructions for all .NET Framework types that are not in the System.Management.Automation namespace.

        The value of this parameter must be the name of a type that is returned by a Get-FormatData command in the session from which the commands are being imported. To get all of the formatting data in the remote session, type *.

        If you use the FormatTypeName parameter, no commands are exported unless you use the CommandName parameter.
        Similarly, if you use the CommandName parameter, the formatting files for the commands are not exported unless you use the FormatTypeName parameter.

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

    -Module <string[]>
        Exports only the commands in the specified Windows PowerShell snap-ins and modules. Enter the snap-in and module names. Wildcards are not permitted.

        For more information, see about_PSSnapins and Import-Module.

        Required?                    false
        Position?                    named
        Default value                All commands in the session.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -OutputModule <string>
        Specifies a path (optional) and name for the module that Export-PSSession creates. The default path is $home\Documents\WindowsPowerShell\Modules. This parameter is required.

        If the module subdirectory or any of the files that Export-PSSession creates already exist, the command fails. To overwrite existing files, use the Force parameter.

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

    -Session <PSSession>
        Specifies the PSSession from which the commands are exported. Enter a Variable that contains a session object or a command that gets a session object, such as a Get-PSSession command. This parameter is required.

        Required?                    true
        Position?                    1
        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
    None
        You cannot pipe objects to Export-PSSession.

OUTPUTS
    System.IO.FileInfo
        Export-PSSession returns a list of files that comprise the module that it created.

NOTES

        Export-PSSession relies on the Windows PowerShell remoting infrastructure. To use this cmdlet, the computer must be configured for remoting. For more information, see about_remote_requirements.

        You cannot use Export-PSSession to export a Windows PowerShell provider.

        Exported commands run implicitly in the PSSession from which they were exported. However, the details of running the commands remotely are handled entirely by Windows PowerShell. You can run the exported commands just as you would run local commands.

        Export-Module captures and saves information about the PSSession in the module that it exports. If the PSSession from which the commands were exported is closed when you import the module, and there are no active PSSessions to the same computer, the commands in the module attempt to re-create the PSSession. If attempts to re-create the PSSession fail, the exported commands will not run.

        The session information that Export-Module captures and saves in the module does not include session options, such as those that you specify in the $PSSessionOption automatic Variable or by using the SessionOption parameters of the New-PSSession, Enter-PSSession, or Invoke-Command cmdlet. If the original PSSession is closed when you import the module, the module will use another PSSession to the same computer, if one is available. To enable the imported commands to run in a correctly configured session, create a PSSession with the options that you want before you import the module.

        To find the commands to export, Export-PSSession uses the Invoke-Command cmdlet to run a Get-Command command in the PSSession. To get and save formatting data for the commands, it uses the Get-FormatData and Export-FormatData cmdlets. You might see error messages from Invoke-Command, Get-Command, Get-FormatData, and Export-FormatData when you run an Export-PSSession command. Also, Export-PSSession cannot export commands from a session that does not include the Get-Command, Get-FormatData, Select-Object, and Get-Help cmdlets.

        Export-PSSession uses the Write-Progress cmdlet to display the progress of the command. You might see the progress bar while the command is running.

        Exported commands have the same limitations as other remote commands, including the inability to start a program with a user interface, such as Notepad.

        Because Windows PowerShell profiles are not run in PSSessions, the commands that a profile adds to a session are not available to Export-PSSession. To export commands from a profile, use an Invoke-Command command to run the profile in the PSSession manually before exporting commands.

        The module that Export-PSSession creates might include a formatting file, even if the command does not import formatting data. If the command does not import formatting data, any formatting files that are created will not contain formatting data.

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

    C:\PS>$s = New-PSSession -computerName Server01

    C:\PS> Export-PSSession -Session $s -OutputModule Server01

    Description
    ———–
    The commands in this example export all commands from a PSSession on the Server01 computer to the Server01 module on the local computer except for commands that have the same names as commands in the current session. It also exports the formatting data for the commands.

    The first command creates a PSSession on the Server01 computer. The second command exports the commands and formatting data from the session into the Server01 module.

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

    C:\PS>$s = New-PSSession -ConnectionUri http://exchange.microsoft.com/mailbox -credential exchangeadmin01@hotmail.com -authentication negotiate

    C:\PS> Export-PSSession -Session $r -Module exch* -CommandName get-*, set-* -FormatTypeName * -OutputModule $pshome\Modules\Exchange -Encoding ASCII

    Description
    ———–
    These commands export the Get and Set commands from a Microsoft Exchange Server snap-in on a remote computer to an Exchange module in the $pshome\Modules directory on the local computer.

    Placing the module in the $pshome\Module directory makes it accessible to all users of the computer.

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

    C:\PS>$s = New-PSSession -computerName Server01 -credential Server01\User01

    C:\PS> Export-PSSession -Session $s -OutputModule TestCmdlets -type cmdlet -CommandName *test* -FormatTypeName *

    C:\PS> Remove-PSSession $s

    C:\PS> Import-Module TestCmdlets

    C:\PS> Get-Help test*

    C:\PS> test-files

    Description
    ———–
    These commands export cmdlets from a PSSession on a remote computer and save them in a module on the local computer. Then, the commands add the cmdlets from the module to the current session so that they can be used.

    The first command creates a PSSession on the Server01 computer and saves it in the $s Variable.

    The second command exports the cmdlets whose names begin with “Test” from the PSSession in $s to the TestCmdlets module on the local computer.

    The third command uses the Remove-PSSession cmdlet to delete the PSSession in $s from the current session. This command shows that the PSSession need not be active to use the commands that were imported from it.

    The fourth command, which can be run in any session at any time, uses the Import-Module cmdlet to add the cmdlets in the TestCmdlets module to the current session.

    The fifth command uses the Get-Help cmdlet to get help for cmdlets whose names begin with “Test.” After the commands in a module are added to the current session, you can use the Get-Help and Get-Command cmdlets to learn about the imported commands, just as you would use them for any command in the session.

    The sixth command uses the Test-Files cmdlet, which was exported from the Server01 computer and added to the session.

    Although it is not evident, the Test-Files command actually runs in a remote session on the computer from which the command was imported. Windows PowerShell creates a session from information that is stored in the module.

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

    C:\PS>Export-PSSession -Session $s -AllowClobber -OutputModule AllCommands

    Description
    ———–
    This command exports all commands and all formatting data from the PSSession in the $s Variable into the current session. The command uses the AllowClobber parameter to include commands with the same names as commands in the current session.

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

    C:\PS>$options = New-PSSessionOption -NoMachineProfile

    C:\PS> $s = New-PSSession -computername Server01 -Sessionoption $options

    C:\PS> Export-PSSession -Session $s -OutputModule Server01

    C:\PS> Remove-PSSession $s

    C:\PS> New-PSSession -computername Server01 -Sessionoption $options

    C:\PS> Import-Module Server01

    Description
    ———–
    This example shows how to run the exported commands in a session with particular options when the PSSession from which the commands were exported is closed.

    When you use Export-PSSession, it saves information about the original PSSession in the module that it creates. When you import the module, if the original remote session is closed, the module will use any open remote session that connects to originating computer.

    If the current session does not include a remote session to the originating computer, the commands in the module will re-establish a session to that computer. However, Export-PSSession does not save special options, such as those set by using the SessionOption parameter of New-PSSession, in the module.

    Therefore, if you want to run the exported commands in a remote session with particular options, you need to create a remote session with the options that you want before you import the module.

    The first command uses the New-PSSessionOption cmdlet to create a PSSessionOption object, and it saves the object in the $options Variable.

    The second command creates a PSSession that includes the specified options. The command uses the New-PSSession cmdlet to create a PSSession on the Server01 computer. It uses the SessionOption parameter to submit the option object in $options.

    The third command uses the Export-PSSession cmdlet to export commands from the PSSession in $s to the Server01 module.

    The fourth command uses the Remove-PSSession cmdlet to delete the PSSession in the $s Variable.

    The fifth command uses the New-PSSession cmdlet to create a new PSSession that connects to the Server01 computer. This PSSession also uses the session options in the $options Variable.

    The sixth command uses the Import-Module cmdlet to import the commands from the Server01 module. The commands in the module run in the PSSession on the Server01 computer.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135213
    about_command_precedence
    Import-PSSession
    New-PSSession
    Import-Module
    Invoke-Command
    about_pssessions