Category Archives: cmdlet

Complete-Transaction

NAME
    Complete-Transaction

SYNOPSIS
    Commits the active transaction.

SYNTAX
    Complete-Transaction [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Complete-Transaction cmdlet commits an active transaction. When you commit a transaction, the commands in the transaction are finalized and the data affected by the commands is changed.

    If the transaction includes multiple subscribers, to commit the transaction, you must enter one Complete-Transaction command for every Start-Transaction command.

    The Complete-Transaction cmdlet is one of a set of cmdlets that support the transactions feature in Windows PowerShell. For more information, see about_transactions.

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

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

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

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

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

INPUTS
    None
        You cannot pipe objects to Complete-Transaction.

OUTPUTS
    None
        This cmdlet does not return any objects.

NOTES

        You cannot roll back a transaction that has been committed, or commit a transaction that has been rolled back.

        You cannot roll back any transaction other than the active transaction. To roll back a different transaction, you must first commit or roll back the active transaction.

        By default, if any part of a transaction cannot be committed, such as when a command in the transaction results in an error, the entire transaction is rolled back.

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

    C:\PS>cd hkcu:\software

    PS HKCU:\software> Start-Transaction

    PS HKCU:\software> New-Item MyCompany -UseTransaction
    PS HKCU:\software> dir m*

     Hive: HKEY_CURRENT_USER\software

    SKC VC Name                         Property
    — — —-                         ——–
     82 1 Microsoft                     {(default)}

    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> dir m*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     82 1 Microsoft                     {(default)}
     0 0 MyCompany                     {}

    Description
    ———–
    This example shows the effect of using the Complete-Transaction cmdlet to commit a transaction.

    The Start-Transaction command starts the transaction. The New-Item command uses the UseTransaction parameter to include the command in the transaction.

    The first “dir” (Get-ChildItem) command shows that the new item has not yet been added to the Registry.

    The Complete-Transaction command commits the transaction, which makes the Registry change effective. As a result, the second “dir” command shows that the Registry is changed.

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

    C:\PS>cd hkcu:\software

    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> New-Item MyCompany -UseTransaction

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     0 0 MyCompany                     {}

    PS HKCU:\software> Start-Transaction
    PS HKCU:\Software> Get-Transaction

    RollbackPreference SubscriberCount Status
    —————— ————— ——
    Error                2                Active

    PS HKCU:\software> New-Itemproperty -path MyCompany -name MyKey -value -UseTransaction

    MyKey
    —–
    123

    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> Get-Transaction

    RollbackPreference SubscriberCount Status
    —————— ————— ——
    Error                1                Active

    PS HKCU:\software> dir m*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     82 1 Microsoft                     {(default)}

    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> dir m*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     82 1 Microsoft                     {(default)}
     0 1 MyCompany                     {MyKey}

    Description
    ———–
    This example shows how to use Complete-Transaction to commit a transaction that has more than one subscriber.

    To commit a multi-subscriber transaction, you must enter one Complete-Transaction command for every Start-Transaction command. The data is changed only when the final Complete-Transaction command is submitted.

    For demonstration purposes, this example shows a series of commands entered at the command line. In practice, transactions are likely to be run in scripts, with the secondary transaction being run by a Function or helper script that is called by the main script.

    In this example, a Start-Transaction command starts the transaction. A New-Item command with the UseTransaction parameter adds the MyCompany key to the Software key. Although the New-Item command returns a key object, the data in the Registry is not yet changed.

    A second Start-Transaction command adds a second subscriber to the existing transaction. The Get-Transaction command confirms that the subscriber count is 2. A New-ItemProperty command with the UseTransaction parameter adds a Registry entry to the new MyCompany key. Again, the command returns a value, but the Registry is not changed.

    The first Complete-Transaction command reduces the subscriber count by 1. This is confirmed by a Get-Transaction command. However, no data is changed, as evidenced by a “dir m*” (Get-ChildItem) command.

    The second Complete-Transaction command commits the entire transaction and changes the data in the Registry. This is confirmed by a second “dir m*” command, which shows the changes.

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

    C:\PS>cd hkcu:\software

    PS HKCU:\software> Start-Transaction

    PS HKCU:\software> New-Item MyCompany -UseTransaction

    PS HKCU:\software> dir m*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     82 1 Microsoft                     {(default)}

    PS HKCU:\software> dir m* -UseTransaction

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     82 1 Microsoft                     {(default)}
     0 0 MyCompany                     {}

    PS HKCU:\software> Complete-Transaction

    Description
    ———–
    This example shows the value of using Get-* commands, and other commands that do not change data, in a transaction. When a Get-* command is used in a transaction, it gets the objects that are part of the transaction. This allows you to preview the changes in the transaction before the changes are committed.

    In this example, a transaction is started. A New-Item command with the UseTransaction parameter adds a new key to the Registry as part of the transaction.

    Because the new Registry key is not added to the Registry until the Complete-Transaction command is run, a simple “dir” (Get-ChildItem) command shows the Registry without the new key.

    However, when you add the UseTransaction parameter to the “dir” command, the command becomes part of the transaction, and it gets the items in the transaction even if they are not yet added to the data.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135200
    about_transactions
    Start-Transaction
    Get-Transaction
    Undo-Transaction
    Use-Transaction

Connect-WSMan

NAME
    Connect-WSMan

SYNOPSIS
    Connects to the WinRM service on a remote computer.

SYNTAX
    Connect-WSMan [-ApplicationName <string>] [-ComputerName <string>] [-Port <int>] [-UseSSL] [-Authentication <Authentication>] [-ComputerName <string>] [-Credential <PSCredential>] [-Port <int>] [-SessionOption <hashtable>] [<CommonParameters>]

    Connect-WSMan [-ConnectionURI <Uri>] [-Authentication <Authentication>] [-ComputerName <string>] [-Credential <PSCredential>] [-Port <int>] [-SessionOption <hashtable>] [<CommonParameters>]

DESCRIPTION
    The Connect-WSMan cmdlet connects to the WinRM service on a remote computer, and it establishes a persistent connection to the remote computer. You can use this cmdlet within the context of the WS-Management provider to connect to the WinRM service on a remote computer. However, you can also use this cmdlet to connect to the WinRM service on a remote computer before you change to the WS-Management provider. The remote computer will appear in the root directory of the WS-Management provider.

    For more information about how to disconnect from the WinRM service on a remote computer, see Disconnect-WSMan.

PARAMETERS
    -ApplicationName <string>
        Specifies the application name in the connection. The default value of the ApplicationName parameter is “WSMAN”. The complete identifier for the remote endpoint is in the following format:
             <transport>://<server>:<port>/<ApplicationName>
        For example:
             http://server01:8080/WSMAN

        Internet Information Services (IIS), which hosts the session, forwards requests with this endpoint to the specified application. This default setting of “WSMAN” is appropriate for most uses. This parameter is designed to be used when numerous computers establish remote connections to one computer that is running Windows PowerShell. In this case, IIS hosts Web Services for Management (WS-Management) for efficiency.

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

    -Authentication <Authentication>
        Specifies the authentication mechanism to be used at the server. Possible values are:

        – Basic: Basic is a scheme in which the user name and password are sent in clear text to the server or proxy.
        – Default : Use the authentication method implemented by the WS-Management protocol. This is the default.
        – Digest: Digest is a challenge-response scheme that uses a server-specified data string for the challenge.
        – Kerberos: The client computer and the server mutually authenticate by using Kerberos Certificates.
        – Negotiate: Negotiate is a challenge-response scheme that negotiates with the server or proxy to determine the scheme to use for authentication. For example, this parameter value allows negotiation to determine whether the Kerberos protocol or NTLM is used.
        – CredSSP: Use Credential Security Service Provider (CredSSP) authentication, which allows the user to delegate credentials. This option is designed for commands that run on one remote computer but collect data from or run additional commands on other remote computers.

        Caution: CredSSP delegates the user’s credentials from the local computer to a remote computer. This practice increases the security risk of the remote operation. If the remote computer is compromised, when credentials are passed to it, the credentials can be used to control the network session.

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

    -ComputerName <string>
        Specifies the computer against which you want to run the management operation. The value can be a fully qualified domain name, a NetBIOS name, or an IP address. Use the local computer name, use localhost, or use a dot (.) to specify the local computer. The local computer is the default. When the remote computer is in a different domain from the user, you must use a fully qualified domain name must be used. You can pipe a value for this parameter to the cmdlet.

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

    -ConnectionURI <Uri>
        Specifies the connection endpoint. The format of this string is:

             <Transport>://<Server>:<Port>/<ApplicationName>.

        The following string is a properly formatted value for this parameter:

             http://Server01:8080/WSMAN. The URI must be fully qualified .

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

    -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”, “Domain01\User01”, or “User@Domain.com”. Or, enter a PSCredential object, such as one returned by the Get-Credential cmdlet. When you type a user name, you will be prompted for a password.

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

    -OptionSet <hashtable>
        Passes a set of switches to the service to modify or refine the nature of the request. These are similar to switches used in command-line shells in that they are service specific. Any number of options can be specified.

        The following example demonstrates the syntax that passes the values 1, 2, and 3 for the a, b, and c parameters:

             -OptionSet @{a=1;b=2;c=3}

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

    -Port <int>
        Specifies the port to use when the client connects to the WinRM service. When the transport is HTTP, the default port is 80. When the transport is HTTPS, the default port is 443. When you use HTTPS as the transport, the value of the ComputerName parameter must match the server’s Certificate common name (CN). However, if the SkipCNCheck parameter is specified as part of the SessionOption parameter, then the Certificate common name of the server does not have to match the host name of the server. The SkipCNCheck parameter should be used only for trusted computers.

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

    -SessionOption <hashtable>
        Defines a set of extended options for the WS-Management session. Enter a SessionOption object that you create by using the New-WSManSessionOption cmdlet. For more information about the options that are available, see New-WSManSessionOption.

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

    -UseSSL [<SwitchParameter>]
        Specifies that the Secure Sockets Layer (SSL) protocol should be used to establish a connection to the remote computer. By default, SSL is not used.

        WS-Management encrypts all the Windows PowerShell content that is transmitted over the network. The UseSSL parameter lets you specify the additional protection of HTTPS instead of HTTP. If SSL is not available on the port that is used for the connection and you specify this parameter, the command fails.

        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
        This cmdlet does not accept any input.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        You can run management commands or query management data on a remote computer without creating a WS-Management session. You can do this by using the ComputerName parameters of Invoke-WSManAction and Get-WSManInstance. When you use the ComputerName parameter, Windows PowerShell creates a temporary connection that is used for the single command. After the command runs, the connection is closed.

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

    C:\PS>Connect-WSMan -computer server01

    PS C:\Users\testuser> cd WSMan:
    PS WSMan:\>
    PS WSMan:\> dir

     WSManConfig: Microsoft.WSMan.Management\WSMan::WSMan

    ComputerName                                 Type
    ————                                 —-
    localhost                                     Container
    server01                                     Container

    Description
    ———–
    This command creates a connection to the remote server01 computer.

    The Connect-WSMan cmdlet is generally used within the context of the WS-Management provider to connect to a remote computer, in this case the server01 computer. However, you can use the cmdlet to establish connections to remote computers before you change to the WS-Management provider. Those connections will appear in the ComputerName list.

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

    C:\PS>$cred = Get-Credential Administrator
    Connect-WSMan -computer server01 -Credential $cred

    PS C:\Users\testuser> cd WSMan:
    PS WSMan:\>
    PS WSMan:\> dir

     WSManConfig: Microsoft.WSMan.Management\WSMan::WSMan

    ComputerName                                 Type
    ————                                 —-
    localhost                                     Container
    server01                                     Container

    Description
    ———–
    This command creates a connection to the remote system server01 using the Administrator account credentials.

    The first command uses the Get-Credential cmdlet to get the Administrator credentials and then stores them in the $cred Variable. The Get-Credential cmdlet prompts the user for a password of username and password. Users are prompted throught a dialog box
    or at the command line, depending on system Registry settings.

    The second command uses the Credential parameter to pass the credentials stored in $cred to Connect-WSMan. Connect-WSMan then connects to the remote system server01 using the Administrator credentials.

    The Connect-WSMan cmdlet is generally used within the context of the WS-Management provider to connect to a remote computer, in this case server01. However, the cmdlet can be used establish connections to remote computers before changing to the WS-Management provider and those connections will show up in the ComputerName list.

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

    C:\PS>Connect-WSMan -computer server01 -Port 80

    PS C:\Users\testuser> cd WSMan:
    PS WSMan:\>
    PS WSMan:\> dir

     WSManConfig: Microsoft.WSMan.Management\WSMan::WSMan

    ComputerName                                 Type
    ————                                 —-
    localhost                                     Container
    server01                                     Container

    Description
    ———–
    This command creates a connection to the remote server01 computer over port 80.

    The Connect-WSMan cmdlet is generally used within the context of the WS-Management provider to connect to a remote computer, in this case the server01 computer. However, you can use the cmdlet to establish connections to remote computers before you change to the WS-Management provider. Those connections will appear in the ComputerName list.

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

    C:\PS>$a = New-WSManSessionOption -operationtimeout 30000
    Connect-WSMan -computer server01 -SessionOption $a

    PS C:\Users\testuser> cd WSMan:
    PS WSMan:\>
    PS WSMan:\> dir

     WSManConfig: Microsoft.WSMan.Management\WSMan::WSMan

    ComputerName                                 Type
    ————                                 —-
    localhost                                     Container
    server01                                     Container

    Description
    ———–
    This command creates a connection to the remote server01 computer by using the connection options that are defined in the New-WSManSessionOption command.

    The first command uses the New-WSManSessionOption cmdlet to store a set of connection setting options in the $a Variable. In this case, the session options set a connection time out of 30 seconds (30,000 milliseconds).

    The second command uses the SessionOption parameter to pass the credentials that are stored in the $a Variable to Connect-WSMan. Then, Connect-WSMan connects to the remote server01 computer by using the specified session options.

    The Connect-WSMan cmdlet is generally used within the context of the WS-Management provider to connect to a remote computer, in this case the server01 computer. However, you can use the cmdlet to establish connections to remote computers before you change to the WS-Management provider. Those connections will appear in the ComputerName list.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkId=141437
    Disable-WSManCredSSP
    Disconnect-WSMan
    Enable-WSManCredSSP
    Get-WSManCredSSP
    Get-WSManInstance
    Invoke-WSManAction
    New-WSManInstance
    New-WSManSessionOption
    Remove-WSManInstance
    Set-WSManInstance
    Set-WSManQuickConfig
    Test-WSMan

Compare-Object

NAME
    Compare-Object

SYNOPSIS
    Compares two sets of objects.

SYNTAX
    Compare-Object [-ReferenceObject] <PSObject[]> [-DifferenceObject] <PSObject[]> [-CaseSensitive] [-Culture <string>] [-ExcludeDifferent] [-IncludeEqual] [-PassThru] [-Property <Object[]>] [-SyncWindow <int>] [<CommonParameters>]

DESCRIPTION
    The Compare-Object cmdlet compares two sets of objects. One set of objects is the Reference set, and the other set is the Difference set.

    The result of the comparison indicates whether a property value appeared only in the object from the Reference set (indicated by the <= symbol), only in the object from the Difference set (indicated by the => symbol) or, if the IncludeEqual parameter is specified, in both objects (indicated by the == symbol).

PARAMETERS
    -CaseSensitive [<SwitchParameter>]
        Indicates that comparisons should be case-sensitive.

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

    -Culture <string>
        Specifies the culture to use for comparisons.

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

    -DifferenceObject <PSObject[]>
        Specifies the objects that are compared to the reference objects.

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

    -ExcludeDifferent [<SwitchParameter>]
        Displays only the characteristics of compared objects that are equal.

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

    -IncludeEqual [<SwitchParameter>]
        Displays characteristics of compared objects that are equal. By default, only characteristics that differ between the reference and difference objects are displayed.

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

    -PassThru [<SwitchParameter>]
        Passes the objects that differed to the pipeline. By default, this cmdlet does not generate any output.

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

    -Property <Object[]>
        Specifies the properties of the reference and difference objects to compare.

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

    -ReferenceObject <PSObject[]>
        Objects used as a reference for comparison.

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

    -SyncWindow <int>
        Defines a search region in which an attempt is made to re-synchronize the order if there is no match. The default value is [Int32]::MaxValue.

        Required?                    false
        Position?                    named
        Default value                [Int32]::MaxValue
        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 a DifferenceObject object to Compare-Object.

OUTPUTS
    None, or the objects that are different
        When you use the PassThru parameter, Compare-Object returns the objects that differed. Otherwise, this cmdlet does not generate any output.

NOTES

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

    C:\PS>Compare-Object -ReferenceObject $(Get-Content C:\test\testfile1.txt) -DifferenceObject $(Get-Content C:\test\testfile2.txt)

    Description
    ———–
    This command compares the contents of two text files. It displays only the lines that appear in one file or in the other file, not lines that appear in both files.

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

    C:\PS>Compare-Object -ReferenceObject $(Get-Content C:\Test\testfile1.txt) -DifferenceObject $(Get-Content C:\Test\testfile2.txt) -IncludeEqual

    Description
    ———–
    This command compares each line of content in two text files. It displays all lines of content from both files, indicating whether each line appears in only Textfile1.txt or Textfile2.txt or whether each line appears in both files.

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

    C:\PS>$processes_before = Get-Process

    C:\PS> notepad

    C:\PS> $processes_after = Get-Process

    C:\PS> Compare-Object -ReferenceObject $processes_before -DifferenceObject $processes_after

    Description
    ———–
    These commands compare two sets of process objects.

    The first command uses the Get-Process cmdlet to get the processes on the computer. It stores them in the $processes_before Variable.

    The second command starts Notepad.

    The third command uses the Get-Process cmdlet again and stores the resulting processes in the $processes_after Variable.

    The fourth command uses the Compare-Object cmdlet to compare the two sets of process objects. It displaysthe differences between them, which include the new instance of Notepad.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113286
    Group-Object
    Measure-Object
    Sort-Object
    ForEach-Object
    New-Object
    Select-Object
    Tee-Object
    Where-Object

Clear-Item

NAME
    Clear-Item

SYNOPSIS
    Deletes the contents of an item, but does not delete the item.

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

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

DESCRIPTION
    The Clear-Item cmdlet deletes the value of an item, but it does not delete the item. For example, Clear-Item can delete the value of a Variable, but it does not delete the Variable. The value that used to represent a cleared item is defined by each Windows PowerShell provider. Clear-Item is similar to Clear-Content, but it works on Aliases and Variables, instead of files.

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.

        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 clear items that cannot otherwise be changed, such as read- only Aliases. The cmdlet cannot clear constants. 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[]>
        Clears 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 the items being cleared. 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 the items being cleared. Wildcards are permitted. This parameter is required, but the parameter name (“Path”) is optional.

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

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

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

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

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

    -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 path string to Clear-Item.

OUTPUTS
    None
        This cmdlet does not return any objects.

NOTES

        The Clear-Item cmdlet is supported only by several Windows PowerShell providers, including the Alias, Environment, Function, Registry, and Variable providers. As such, you can use Clear-Item to delete the content of items in the provider namespaces.

        You cannot use Clear-Item to delete the contents of a file, because the Windows PowerShell FileSystem provider does not support this cmdlet. To clear files, use Clear-Content.

        You can also refer to Clear-Item by its built-in Alias, “cli”. For more information, type “Get-Help about_aliases“.

        The Clear-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>Clear-Item Variable:TestVar1

    Description
    ———–
    This command deletes the value of the Variable, Testvar1. The Variable remains and is valid, but its value is set to null.

    The Variable name is prefixed with “Variable:” to indicate the Windows PowerShell Variable provider. To get the same result, you can switch to the Windows PowerShell Variable provider namespace first and then perform the Clear-Item command.

        PS C:> Set-Location Variable:
        PS Variable:\> Clear-Item Testvar1

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

    C:\PS>Clear-Item Alias:log* -Include *1* -Exclude *3* -WhatIf

    What if: Performing operation “Clear Item” on Target “Item: log1”.

    Description
    ———–
    This command asks Windows PowerShell what would happen if you executed the command, “Clear-Item Alias:log* -Include *1* -Exclude *3″. In response, Windows PowerShell explains that it would delete the value of the log1 Alias.

    This command would not have any effect on the log, log2, or log13 Aliases. Because the Alias provider does not permit an Alias without a value, when you clear an Alias, you also delete the Alias.

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

    C:\PS>Clear-Item Registry::HKLM\Software\MyCompany\MyKey -Confirm

    Description
    ———–
    This command deletes all Registry entries in the MyKey subkey, but only after prompting you to confirm your intent. It does not delete the MyKey subkey or affect any other Registry keys or entries. You can use the Include and Exclude parameters to identify particular Registry keys, but you cannot use them to identify Registry entries. To delete particular Registry entries, use Remove-ItemProperty. To delete the value of a Registry entry, use Clear-ItemProperty.

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

Clear-ItemProperty

NAME
    Clear-ItemProperty

SYNOPSIS
    Deletes the value of a property but does not delete the property.

SYNTAX
    Clear-ItemProperty [-LiteralPath] <string[]> [-Name] <string> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Clear-ItemProperty [-Path] <string[]> [-Name] <string> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Clear-ItemProperty cmdlet deletes the value of a property, but it does not delete the property. You can use this cmdlet to delete the data from a Registry value.

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” or “s*”. 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>]
        Allows the cmdlet to delete properties from items that cannot otherwise be accessed by the user. Implementation varies from provider to provider. For more information, see about_providers.

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

    -Include <string[]>
        Clears 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 the property being cleared. 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 <string>
        Specifies the name of the property to be cleared, such as the name of a Registry value. Wildcards are not permitted.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing the cleared item’s property. By default, this cmdlet does not generate any output.

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

    -Path <string[]>
        Specifies the path to the property being cleared. Wildcards are permitted.

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

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

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

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

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

    -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 path string to Clear-ItemProperty.

OUTPUTS
    None or System.Management.Automation.PSCustomObject
        When you use the PassThru parameter, Clear-ItemProperty generates a PSCustomObject object that represents the cleared item property. Otherwise, this cmdlet does not generate any output.

NOTES

        You can use Clear-ItemProperty to delete the data in Registry values without deleting the value. If the data type of the value is Binary or DWORD, clearing the data sets the value to zero. Otherwise, the value is empty.

        You can also refer to Clear-ItemProperty by its built-in Alias, “clp”. For more information, see about_aliases.

        The Clear-ItemProperty 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>Clear-Itemproperty -Path HKLM:\Software\MyCompany\MyApp -Name Options

    Description
    ———–
    This command deletes the data in the Options Registry value in the MyApp subkey of HKEY_LOCAL_MACHINE\Software\MyCompany.

    Because the command is being issued from a file system drive (C:), it uses the fully qualified path to the HKLM: drive and the Software\MyCompany\MyApp subkey. It uses the Name parameter to specify the Options value.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113284
    about_providers
    Copy-ItemProperty
    New-ItemProperty
    Move-ItemProperty
    Rename-ItemProperty
    Get-ItemProperty
    New-ItemProperty

Clear-Variable

NAME
    Clear-Variable

SYNOPSIS
    Deletes the value of a Variable.

SYNTAX
    Clear-Variable [-Name] <string[]> [-Exclude <string[]>] [-Force] [-Include <string[]>] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Clear-Variable cmdlet deletes the data stored in a Variable, but it does not delete the Variable. As a result, the value of the Variable is NULL (empty). If the Variable has a specified data or object type, Clear-Variable preserves the type of the object stored in the Variable.

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

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to clear a Variable even if it is read-only. Even using the Force parameter, the cmdlet cannot clear constants.

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

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

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

    -Name <string[]>
        Specifies the name of the Variable to be cleared. Wildcards are permitted. This parameter is required, but the parameter name (“Name”) is optional.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing the cleared Variable. By default, this cmdlet does not generate any output.

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

    -Scope <string>
        Specifies the scope in which this Alias is valid. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

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

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

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

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

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

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

INPUTS
    None
        You cannot pipe objects to Clear-Variable.

OUTPUTS
    None or System.Management.Automation.PSVariable
        When you use the PassThru parameter, Clear-Variable generates a System.Management.Automation.PSVariable object representing the cleared Variable. Otherwise, this cmdlet does not generate any output.

NOTES

        To delete a Variable, along with its value, use Remove-Variable or Remove-Item.

        Clear-Variable will not delete the values of Variables that are set as constants or owned by the system, even if you use the -Force parameter.

        If the Variable that you are clearing does not exist, the cmdlet has no effect. It does not create a Variable with a null value.

        You can also refer to Clear-Variable by its built-in Alias, “clv”. For more information, see about_aliases.

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

    C:\PS>Clear-Variable my* -global

    Description
    ———–
    This command deletes the value of the global Variables that begin with “my”.

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

    C:\PS>$a=3

    C:\PS>&{ Clear-Variable a }

    C:\PS>$a
    3

    Description
    ———–
    These commands demonstrate that clearing a Variable in a child scope does not clear the value in the parent scope. The first command sets the value of the Variable $a to “3”. The second command uses the invoke operator (&) to run a Clear-Variable command in a new scope. The Variable is cleared in the child scope (although it did not exist), but it is not cleared in the local scope. The third command, which gets the value of $a, shows that the value “3” is unaffected.

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

    C:\PS>Clear-Variable -Name processes

    Description
    ———–
    This command deletes the value of the $processes Variable. The $processes Variable still exists, but the value is null.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113285
    Get-Variable
    Set-Variable
    New-Variable
    Remove-Variable

Clear-Content

NAME
    Clear-Content

SYNOPSIS
    Deletes the contents of an item, such as deleting the text from a file, but does not delete the item.

SYNTAX
    Clear-Content [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Clear-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Clear-Content cmdlet deletes the contents of an item, such as deleting the text from a file, but it does not delete the item. As a result, the item exists, but it is empty. Clear-Content is similar to Clear-Item, but it works on files instead of on Aliases and Variables.

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.

        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 clear the file contents even if the file is read-only. 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[]>
        Clears 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 paths to the items from which content is deleted. 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 paths to the items from which content is deleted. Wildcards are permitted. The paths must be paths to items, not to containers. For example, you must specify a path to one or more files, not a path to a directory. Wildcards are permitted. This parameter is required, but the parameter name (“Path”) is optional.

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

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

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

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

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

    -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 objects to Clear-Content.

OUTPUTS
    None
        This cmdlet does not return any objects.

NOTES

        You can also refer to Clear-Content by its built-in Alias, “clc”. For more information, see about_aliases.

        If you omit the -Path parameter name, the value of Path must be the first parameter in the command. For example, “Clear-Content c:\mydir\*.txt”. If you include the parameter name, you can list the parameters in any order.

        You can use Clear-Content with the Windows PowerShell File System provider and with other providers that manipulate content. To clear items that are not considered to be content, such as items managed by the Windows PowerShell Certificate or Registry providers, use Clear-Item.

        The Clear-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>Clear-Content ..\SmpUsers\*\init.txt

    Description
    ———–
    This command deletes all of the content from the “init.txt” files in all subdirectories of the SmpUsers directory. The files are not deleted, but they are empty.

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

    C:\PS>Clear-Content -Path * -Filter *.log -Force

    Description
    ———–
    This command deletes the contents of all files in the current directory with the “.log” file name extension, including files with the read-only attribute. The asterisk (*) in the path represents all items in the current directory. The Force parameter makes the command effective on read-only files. Using a filter to restrict the command to files with the “.log” file name extension instead of specifying “*.log” in the path makes the operation faster.

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

    C:\PS>Clear-Content c:\Temp\* -Include Smp* -Exclude *2* -WhatIf

    Description
    ———–
    This command requests a prediction of what would happen if you submitted the command: “Clear-Content c:\temp\* -Include smp* -Exclude *2*”. The result lists the files that would be cleared; in this case, files in the Temp directory whose names begin with “Smp”, unless the file names include a “2”. To execute the command, run it again without the Whatif parameter.

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

Clear-EventLog

NAME
    Clear-EventLog

SYNOPSIS
    Deletes all entries from specified event logs on the local or remote computers.

SYNTAX
    Clear-EventLog [-LogName] <string[]> [[-ComputerName] <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Clear-EventLog cmdlet deletes all of the entries from the specified event logs on the local computer or on remote computers. To use Clear-EventLog, you must be a member of the Administrators group on the affected computer.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -ComputerName <string[]>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    2
        Default value                Local computer
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -LogName <string[]>
        Specifies the event logs. Enter the log name (the value of the Log property; not the LogDisplayName) of one or more event logs, separated by commas. Wildcard characters are not permitted. This parameter is required.

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

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

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

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

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

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

INPUTS
    None
        You cannot pipe objects to Clear-EventLog.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        To use Clear-EventLog on Windows Vista and later versions of Windows, start Windows PowerShell with the “Run as administrator” option.

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

    C:\PS>Clear-EventLog “Windows PowerShell”

    Description
    ———–
    This command deletes the entries from the “Windows PowerShell” event log on the local computer.

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

    C:\PS>Clear-EventLog -LogName ODiag, OSession -ComputerName localhost, Server02

    Description
    ———–
    This command deletes all of the entries in the Microsoft Office Diagnostics (ODiag) and Microsoft Office Sessions (OSession) logs on the local computer and the Server02 remote computer.

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

    C:\PS>Clear-EventLog -log application, system -Confirm

    Description
    ———–
    This command prompts you for confirmation before deleting the entries in the specified event logs.

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

    C:\PS>function clear-all-event-logs ($computerName=”localhost”)
    {
        $logs = Get-Eventlog -ComputerName $computername -list | foreach {$_.Log}
        $logs | foreach {Clear-EventLog -comp $computername -log $_ }
        Get-Eventlog -ComputerName $computername -list
    }

    C:\PS> clear-all-event-logs -comp Server01

     Max(K) Retain OverflowAction        Entries Log
     —— —— ————–        ——- —
     15,168     0 OverwriteAsNeeded         0 Application
     15,168     0 OverwriteAsNeeded         0 DFS Replication
         512     7 OverwriteOlder             0 DxStudio
     20,480     0 OverwriteAsNeeded         0 Hardware Events
         512     7 OverwriteOlder             0 Internet Explorer
     20,480     0 OverwriteAsNeeded         0 Key Management Service
     16,384     0 OverwriteAsNeeded         0 Microsoft Office Diagnostics
     16,384     0 OverwriteAsNeeded         0 Microsoft Office Sessions
     30,016     0 OverwriteAsNeeded         1 Security
     15,168     0 OverwriteAsNeeded         2 System
     15,360     0 OverwriteAsNeeded         0 Windows PowerShell

    Description
    ———–
    This Function clears all event logs on the specified computers and then displays the resulting event log list.

    Notice that a few entries were added to the System and Security logs after the logs were cleared but before they were displayed.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135198
    Get-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

Clear-History

NAME
    Clear-History

SYNOPSIS
    Deletes entries from the command history.

SYNTAX
    Clear-History [[-Id] <Int32[]>] [[-Count] <int>] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]

    Clear-History [[-Count] <int>] [-CommandLine <string[]>] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Clear-History cmdlet deletes commands from the command history, that is, the list of commands entered during the current session.

    Without parameters, Clear-History deletes all commands from the session history, but you can use the parameters of Clear-History to delete selected commands.

PARAMETERS
    -CommandLine <string[]>
        Deletes commands with the specified text strings. If you enter more than one string, Clear-History deletes commands with any of the strings.

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

    -Count <int>
        Clears the specified number of history entries, beginning with the oldest entry in the history.

        If you use the Count and Id parameters in the same command, the cmdlet clears the number of entries specified by the Count parameter, beginning with the entry specified by the Id parameter. For example, if Count is 10 and Id is 30, Clear-History clears items 21 through 30 inclusive.

        If you use the Count and CommandLine parameters in the same command, Clear-History clears the number of entries specified by the Count parameter, beginning with the entry specified by the CommandLine parameter.

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

    -Id <Int32[]>
        Deletes commands with the specified history IDs.

        To find the history ID of a command, use Get-History.

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

    -Newest [<SwitchParameter>]
        Deletes the newest entries in the history. By default, Clear-History deletes the oldest entries in the history.

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

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

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

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

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

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

INPUTS
    None
        You cannot pipe objects to Clear-History.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        The session history is a list of the commands entered during the session. You can view the history, add and delete commands, and run commands from the history. For more information, see about_History.

        Deleting a command from the history does not change the history IDs of the remaining items in the command history.

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

    C:\PS>Clear-History

    Description
    ———–
    Deletes all commands from the session history.

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

    C:\PS>Clear-History -Id 23, 25

    Description
    ———–
    Deletes the commands with history IDs 23 and 25.

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

    C:\PS>Clear-History -command *help*, *command

    Description
    ———–
    Deletes commands that include “help” or end in “command”.

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

    C:\PS>Clear-History -Count 10 -Newest

    Description
    ———–
    Deletes the 10 newest commands from the history.

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

    C:\PS>Clear-History -Id 10 -Count 3

    Description
    ———–
    Deletes the three oldest commands, beginning with the entry with ID 10.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135199
    about_History
    Get-History
    Add-History
    Invoke-History

Add-Type

NAME
    Add-Type

SYNOPSIS
    Adds a Microsoft .NET Framework type (a class) to a Windows PowerShell session.

SYNTAX
    Add-Type -AssemblyName <string[]> [-IgnoreWarnings] [-PassThru] [<CommonParameters>]

    Add-Type [-Name] <string> [-MemberDefinition] <string[]> [-CodeDomProvider <CodeDomProvider>] [-CompilerParameters <CompilerParameters>] [-Language {CSharp | CSharpVersion3 | VisualBasic | JScript}] [-Namespace <string>] [-OutputAssembly <string>] [-OutputType <OutputAssemblyType>] [-ReferencedAssemblies <string[]>] [-UsingNamespace <string[]>] [-IgnoreWarnings] [-PassThru] [<CommonParameters>]

    Add-Type [-Path] <string[]> [-CompilerParameters <CompilerParameters>] [-OutputAssembly <string>] [-OutputType <OutputAssemblyType>] [-ReferencedAssemblies <string[]>] [-IgnoreWarnings] [-PassThru] [<CommonParameters>]

    Add-Type [-TypeDefinition] <string> [-CodeDomProvider <CodeDomProvider>] [-CompilerParameters <CompilerParameters>] [-Language {CSharp | CSharpVersion3 | VisualBasic | JScript}] [-OutputAssembly <string>] [-OutputType <OutputAssemblyType>] [-ReferencedAssemblies <string[]>] [-IgnoreWarnings] [-PassThru] [<CommonParameters>]

DESCRIPTION
    The Add-Type cmdlet lets you define a .NET Framework class in your Windows PowerShell session. You can then instantiate objects (by using the New-Object cmdlet) and use the objects, just as you would use any .NET Framework object. If you add an Add-Type command to your Windows PowerShell profile, the class will be available in all Windows PowerShell sessions.

    You can specify the type by specifying an existing assembly or source code files, or you can specify the source code inline or saved in a Variable. You can even specify only a method and Add-Type will define and generate the class. You can use this feature to make Platform Invoke (P/Invoke) calls to unmanaged Functions in Windows PowerShell. If you specify source code, Add-Type compiles the specified source code and generates an in-memory assembly that contains the new .NET Framework types.

    You can use the parameters of Add-Type to specify an alternate language and compiler (CSharp is the default), compiler options, assembly dependencies, the class namespace, the names of the type, and the resulting assembly.

PARAMETERS
    -AssemblyName <string[]>
        Specifies the name of an assembly that includes the types. Add-Type takes the types from the specified assembly. This parameter is required when you are creating types based on an assembly name.

        Enter the full or simple name (also known as the “partial name”) of an assembly. Wildcard characters are permitted in the assembly name. If you enter a simple or partial name, Add-Type resolves it to the full name, and then uses the full name to load the assembly.

        This parameter does not accept a path or file name. To enter the path to the assembly dynamic-link library (DLL) file, use the Path parameter.

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

    -CodeDomProvider <CodeDomProvider>
        Specifies a code generator or compiler. Add-Type uses the specified compiler to compile the source code. The default is the CSharp compiler. Use this parameter if you are using a language that cannot be specified by using the Language parameter. The CodeDomProvider that you specify must be able to generate assemblies from source code.

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

    -CompilerParameters <CompilerParameters>
        Specifies the options for the source code compiler. These options are sent to the compiler without revision.

        This parameter allows you to direct the compiler to generate an executable file, embed resources, or set command-line options, such as the “/unsafe” option. This parameter implements the CompilerParameters class (System.CodeDom.Compiler.CompilerParameters).

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

    -IgnoreWarnings [<SwitchParameter>]
        Ignores compiler warnings. Use this parameter to prevent Add-Type from handling compiler warnings as errors.

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

    -Language <Language>
        Specifies the language used in the source code. Add-Type uses the language to select the correct code compiler.

        Valid values are “CSharp”, “CSharpVersion3”, “VisualBasic”, and “JScript”. “CSharp” is the default.

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

    -MemberDefinition <string[]>
        Specifies new properties or methods for the class. Add-Type generates the template code that is required to support the properties or methods.

        You can use this feature to make Platform Invoke (P/Invoke) calls to unmanaged Functions in Windows PowerShell. For more information, see the examples.

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

    -Name <string>
        Specifies the name of the class to create. This parameter is required when generating a type from a member definition.

        The type name and namespace must be unique within a session. You cannot unload a type or change it. If you need to change the code for a type, you must change the name or start a new Windows PowerShell session. Otherwise, the command fails.

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

    -Namespace <string>
        Specifies a namespace for the type.

        If this parameter is not included in the command, the type is created in the Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes namespace. If the parameter is included in the command with an empty string value or a value of $null, the type is generated in the global namespace.

        Required?                    false
        Position?                    named
        Default value                Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes
        Accept pipeline input?     false
        Accept wildcard characters? false

    -OutputAssembly <string>
        Generates a DLL file for the assembly with the specified name in the location. Enter a path (optional) and file name. Wildcard characters are permitted. By default, Add-Type generates the assembly only in memory.

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

    -OutputType <OutputAssemblyType>
        Specifies the output type of the output assembly. Valid values are Library, ConsoleApplication, and WindowsApplication.
        By default, no output type is specified.

        This parameter is valid only when an output assembly is specified in the command.

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

    -PassThru [<SwitchParameter>]
        Returns a System.Runtime object that represents the types that were added. By default, this cmdlet does not generate any output.

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

    -Path <string[]>
        Specifies the path to source code files or assembly DLL files that contain the types.

        If you submit source code files, Add-Type compiles the code in the files and creates an in-memory assembly of the types. The file name extension specified in the value of Path determines the compiler that Add-Type uses.

        If you submit an assembly file, Add-Type takes the types from the assembly. To specify an in-memory assembly or the global assembly cache, use the AssemblyName parameter.

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

    -ReferencedAssemblies <string[]>
        Specifies the assemblies upon which the type depends. By default, Add-Type references System.dll and System.Management.Automation.dll. The assemblies that you specify by using this parameter are referenced in addition to the default assemblies.

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

    -TypeDefinition <string>
        Specifies the source code that contains the type definitions. Enter the source code in a string or here-string, or enter a Variable that contains the source code. For more information about here-strings, see about_Quoting_Rules.

        Include a namespace declaration in your type definition. If you omit the namespace declaration, your type might have the same name as another type or the shortcut for another type, causing an unintentional overwrite. For example, if you define a type called “Exception”, scripts that use “Exception” as the shortcut for System.Exception will fail.

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

    -UsingNamespace <string[]>
        Specifies other namespaces that are required for the class. This is much like the Using keyword in C#.

        By default, Add-Type references the System namespace. When the MemberDefinition parameter is used, Add-Type also references the System.Runtime.InteropServices namespace by default. The namespaces that you add by using the UsingNamespace parameter are referenced in addition to the default namespaces.

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

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

INPUTS
    None
        You cannot pipe objects to Add-Type.

OUTPUTS
    None or System.RuntimeType
        When you use the PassThru parameter, Add-Type returns a System.RuntimeType object that represents the new type. Otherwise, this cmdlet does not generate any output.

NOTES

        The types that you add exist only in the current session. To use the types in all sessions, add them to your Windows PowerShell profile. For more information about the profile, see about_profiles.

        Type names (and namespaces) must be unique within a session. You cannot unload a type or change it. If you need to change the code for a type, you must change the name or start a new Windows PowerShell session. Otherwise, the command fails.

        The CodeDomProvider class for some languages, such as IronPython and JSharp, does not generate output. As a result, types written in these languages cannot be used with Add-Type.

        This cmdlet is based on the CodeDomProvider class. For more information about this class, see the Microsoft .NET Framework SDK.

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

    C:\PS>$source = @”
    public class BasicTest
    {
        public static int Add(int a, int b)
        {
            return (a + b);
        }

        public int Multiply(int a, int b)
        {
            return (a * b);
        }
    }
    “@

    C:\PS> Add-Type -TypeDefinition $source

    C:\PS> [BasicTest]::Add(4, 3)

    C:\PS> $basicTestObject = New-Object BasicTest
    C:\PS> $basicTestObject.Multiply(5, 2)

    Description
    ———–
    These commands add the BasicTest class to the session by specifying source code that is stored in a Variable. The type has a static method called Add and a non-static method called Multiply.

    The first command stores the source code for the class in the $source Variable.

    The second command uses the Add-Type cmdlet to add the class to the session. Because it is using inline source code, the command uses the TypeDefinition parameter to specify the code in the $source Variable.

    The remaining commands use the new class.

    The third command calls the Add static method of the BasicTest class. It uses the double-colon characters (::) to specify a static member of the class.

    The fourth command uses the New-Object cmdlet to instantiate an instance of the BasicTest class. It saves the new object in the $basicTestObject Variable.

    The fifth command uses the Multiply method of $basicTestObject.

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

    C:\PS>[BasicTest] | Get-Member

    C:\PS> [BasicTest] | Get-Member -static

    C:\PS> $basicTestObject | Get-Member

    C:\PS> [BasicTest] | Get-Member

     TypeName: System.RuntimeType

    Name                         MemberType Definition
    —-                         ———- ———-
    Clone                         Method     System.Object Clone()
    Equals                         Method     System.Boolean Equals
    FindInterfaces                 Method     System.Type[] FindInt
    …

    C:\PS> [BasicTest] | Get-Member -static

     TypeName: BasicTest

    Name            MemberType Definition
    —-            ———- ———-
    Add             Method     static System.Int32 Add(Int32 a, Int32 b)
    Equals         Method     static System.Boolean Equals(Object objA,
    ReferenceEquals Method     static System.Boolean ReferenceEquals(Obj

    C:\PS> $basicTestObject | Get-Member

     TypeName: BasicTest

    Name        MemberType Definition
    —-        ———- ———-
    Equals     Method     System.Boolean Equals(Object obj)
    GetHashCode Method     System.Int32 GetHashCode()
    GetType     Method     System.Type GetType()
    Multiply    Method     System.Int32 Multiply(Int32 a, Int32 b)
    ToString    Method     System.String ToString()

    Description
    ———–
    These commands use the Get-Member cmdlet to examine the objects that the Add-Type and New-Object cmdlets created in the previous example.

    The first command uses the Get-Member cmdlet to get the type and members of the BasicTest class that Add-Type added to the session. The Get-Member command reveals that it is a System.RuntimeType object, which is derived from the System.Object class.

    The second command uses the Static parameter of Get-Member to get the static properties and methods of the BasicTest class. The output shows that the Add method is included.

    The third command uses Get-Member to get the members of the object stored in the $BasicTestObject Variable. This was the object instance that was created by using the New-Object cmdlet with the $BasicType class.

    The output reveals that the value of the $basicTestObject Variable is an instance of the BasicTest class and that it includes a member called Multiply.

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

    C:\PS>$accType = Add-Type -assemblyname accessib* -PassThru

    Description
    ———–
    This command adds the classes from the Accessibility assembly to the current session. The command uses the AssemblyName parameter to specify the name of the assembly. The wildcard character allows you to get the correct assembly even when you are not sure of the name or its spelling.

    The command uses the PassThru parameter to generate objects that represent the classes that are added to the session, and it saves the objects in the $accType Variable.

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

    C:\PS>Add-Type -path c:\ps-test\Hello.vb

    [VBFromFile]::SayHello(“, World”)

    # From Hello.vb
    Public Class VBFromFile

    Public Shared Function SayHello(sourceName As String) As String
    Dim myValue As String = “Hello”

    return myValue + sourceName
    End Function
    End Class

    C:\PS> [VBFromFile]::SayHello(“, World”)
    Hello, World

    Description
    ———–
    This example uses the Add-Type cmdlet to add the VBFromFile class that is defined in the Hello.vb file to the current session. The text of the Hello.vb file is shown in the command output.

    The first command uses the Add-Type cmdlet to add the type defined in the Hello.vb file to the current session. The command uses the path parameter to specify the source file.

    The second command calls the SayHello Function as a static method of the VBFromFile class.

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

    C:\PS>$signature = @”
    [DllImport(“user32.dll”)]
    public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    “@

    $showWindowAsync = Add-Type -memberDefinition $signature -name “Win32ShowWindowAsync” -namespace Win32Functions -PassThru

    # Minimize the Windows PowerShell console
    $showWindowAsync::ShowWindowAsync((Get-Process -id $pid).MainWindowHandle, 2)

    # Restore it
    $showWindowAsync::ShowWindowAsync((Get-Process -id $pid).MainWindowHandle, 4)

    Description
    ———–
    The commands in this example demonstrate how to call native Windows APIs in Windows PowerShell. Add-Type uses the Platform Invoke (P/Invoke) mechanism to call a Function in User32.dll from Windows PowerShell.

    The first command stores the C# signature of the ShowWindowAsync Function in the $signature Variable. (For more information, see “ShowWindowAsync Function” in the MSDN library at http://go.microsoft.com/fwlink/?LinkId=143643.) To ensure that the resulting method will be visible in a Windows PowerShell session, the “public” keyword has been added to the standard signature.

    The second command uses the Add-Type cmdlet to add the ShowWindowAsync Function to the Windows PowerShell session as a static method of a class that Add-Type creates. The command uses the MemberDefinition parameter to specify the method definition saved in the $signature Variable.

    The command uses the Name and Namespace parameters to specify a name and namespace for the class. It uses the PassThru parameter to generate an object that represents the types, and it saves the object in the $showWindowAsync Variable.

    The third and fourth commands use the new ShowWindowAsync static method. The method takes two parameters, the window handle, and an integer specifies how the window is to be shown.

    The third command calls ShowWindowAsync. It uses the Get-Process cmdlet with the $pid automatic Variable to get the process that is hosting the current Windows PowerShell session. Then it uses the MainWindowHandle property of the current process and a value of “2”, which represents the SW_MINIMIZE value.

    To restore the window, the fourth command use a value of “4” for the window position, which represents the SW_RESTORE value. (SW_MAXIMIZE is 3.)

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

    C:\PS>Add-Type -MemberDefinition $jsMethod -Name “PrintInfo” -Language JScript

    Description
    ———–
    This command uses the Add-Type cmdlet to add a method from inline JScript code to the Windows PowerShell session. It uses the MemberDefinition parameter to submit source code stored in the $jsMethod Variable. It uses the Name Variable to specify a name for the class that Add-Type creates for the method and the Language parameter to specify the JScript language.

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

    C:\PS>Add-Type -Path FSharp.Compiler.CodeDom.dll

    C:\PS> Add-Type -Path FSharp.Compiler.CodeDom.dll
    C:\PS> $provider = New-Object Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider

    C:\PS> $fSharpCode = @”
    let rec loop n =
    if n <= 0 then () else begin
    print_endline (string_of_int n);
    loop (n-1)
    end
    “@

    C:\PS> $fsharpType = Add-Type -TypeDefinition $fSharpCode -CodeDomProvider $provider -PassThru | where { $_.IsPublic }
    C:\PS> $fsharpType::loop(4)
    4
    3
    2
    1

    Description
    ———–
    This example shows how to use the Add-Type cmdlet to add an FSharp code compiler to your Windows PowerShell session. To run this example in Windows PowerShell, you must have the FSharp.Compiler.CodeDom.dll that is installed with the FSharp language.

    The first command in the example uses the Add-Type cmdlet with the Path parameter to specify an assembly. Add-Type gets the types in the assembly.

    The second command uses the New-Object cmdlet to create an instance of the FSharp code provider and saves the result in the $provider Variable.

    The third command saves the FSharp code that defines the Loop method in the $FSharpCode Variable.

    The fourth command uses the Add-Type cmdlet to save the public types defined in $fSharpCode in the $fSharpType Variable. The TypeDefinition parameter specifies the source code that defines the types. The CodeDomProvider parameter specifies the source code compiler.

    The PassThru parameter directs Add-Type to return a Runtime object that represents the types and a pipeline operator (|) sends the Runtime object to the Where-Object cmdlet, which returns only the public types. The Where-Object filter is used because the FSharp provider generates non-public types to support the resulting public type.

    The fifth command calls the Loop method as a static method of the type stored in the $fSharpType Variable.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135195
    Add-Member
    New-Object