Tag Archives: PassThru

Add-PSSnapin

NAME
    Add-PSSnapin

SYNOPSIS
    Adds one or more Windows PowerShell snap-ins to the current session.

SYNTAX
    Add-PSSnapin [-Name] <string[]> [-PassThru] [<CommonParameters>]

DESCRIPTION
    The Add-PSSnapin cmdlet adds registered Windows PowerShell snap-ins to the current session. After the snap-ins are added, you can use the cmdlets and providers that the snap-ins support in the current session.

    To add the snap-in to all future Windows PowerShell sessions, add an Add-PSSnapin command to your Windows PowerShell profile. For more information, see about_profiles.

PARAMETERS
    -Name <string[]>
        Specifies the name of the snap-in. (This is the Name, not the AssemblyName or ModuleName.)

        To find the names of the registered snap-ins on your system, type: “Get-PSSnapin -registered”.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing each added snap-in. By default, this cmdlet does not generate any output.

        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-PSSnapin.

OUTPUTS
    None or System.Management.Automation.PSSnapInInfo
        When you use the PassThru parameter, Add-PSSnapin returns a PSSnapInInfo object that represents the snap-in. Otherwise, this cmdlet does not generate any output.

NOTES

        For detailed information about snap-ins in Windows PowerShell, see about_PSSnapins. For information about how to create a Windows PowerShell snap-in, see “How to Create a Windows PowerShell Snap-in” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=144762.

        Add-PSSnapin adds the snap-in only to the current session. To add the snap-in to all Windows PowerShell sessions, add it to your Windows PowerShell profile. For more information, see about_profiles.

        You can add any Windows PowerShell snap-in that has been registered by using the Microsoft .NET Framework install utility. For more information, see “How to Register Cmdlets, Providers, and Host Applications” in the MSDN library at http://go.microsoft.com/fwlink/?LinkID=143619.

        To get a list of snap-ins that are registered on your computer, type “Get-PSSnapin -registered”.

        Before adding a snap-in, Add-PSSnapin checks the version of the snap-in to verify that it is compatible with the current version of Windows PowerShell. If the snap-in fails the version check, Windows PowerShell reports an error.

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

    C:\PS>Add-PSSnapin Microsoft.Exchange, Microsoft.Windows.AD

    Description
    ———–
    This command adds the Microsoft Exchange and Active Directory snap-ins to the current session.

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

    C:\PS>Get-PSSnapin -registered | Add-PSSnapin -PassThru

    Description
    ———–
    This command adds all of the registered Windows PowerShell snap-ins to the session. It uses the Get-PSSnapin cmdlet with the Registered parameter to get objects representing each of the registered snap-ins. The pipeline operator (|) passes the result to Add-PSSnapin, which adds them to the session. The PassThru parameter returns objects that represent each of the added snap-ins.

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

    C:\PS>Get-PSSnapin

    Description
    ———–
    This example demonstrates the process of registering a snap-in on your system and then adding it to your session. It uses ManagementFeatures, a fictitious snap-in implemented in a file called ManagementCmdlets.dll.

    The first command gets snap-ins that have been added to the current session, including the snap-ins that are installed with Windows PowerShell. In this example, ManagementFeatures is not returned. This indicates that it has not been added to the session.

        Get-PSSnapin

    The second command gets snap-ins that have been registered on your system (including those that have already been added to the session). It does not include the snap-ins that are installed with Windows PowerShell.

        Get-PSSnapin -registered

    In this case, the command does not return any snap-ins. This indicates that the ManagementFeatures snapin has not been registered on the system.

    The third command creates an Alias, “installutil”, for the path to the InstallUtil tool in the .NET Framework.

        Set-Alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe

    The fourth command uses the InstallUtil tool to register the snap-in. The command specifies the path to ManagementCmdlets.dll, the file name or “module name” of the snap-in.

        installutil C:\Dev\Management\ManagementCmdlets.dll

    The fifth command is the same as the second command. This time, you use it to verify that the ManagementCmdlets snap-in is registered.

        Get-PSSnapin -registered

    The sixth command uses the Add-PSSnapin cmdlet to add the ManagementFeatures snap-in to the session. It specifies the name of the snap-in, ManagementFeatures, not the file name.

        Add-PSSnapin ManagementFeatures

    To verify that the snap-in is added to the session, the seventh command uses the Module parameter of the Get-Command cmdlet. It displays the items that were added to the session by a snap-in or module.

        Get-Command -module ManagementFeatures

    You can also use the PSSnapin property of the object that Get-Command returns to find the snap-in or module in which a cmdlet originated. The eighth command uses dot notation to find the value of the PSSnapin property of the Set-Alias command.

        (Get-Command Set-Alias).pssnapin

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

Add-Content

NAME
    Add-Content

SYNOPSIS
    Adds content to the specified items, such as adding words to a file.

SYNTAX
    Add-Content [-LiteralPath] <string[]> [-Value] <Object[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Add-Content [-Path] <string[]> [-Value] <Object[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Add-Content cmdlet appends content to a specified item or file. You can specify the content by typing the content in the command or by specifying an object that contains the content.

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>]
        Overrides the read-only attribute, allowing you to add content to a read-only file.

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

    -Include <string[]>
        Adds 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 that receive the additional content. 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

    -PassThru [<SwitchParameter>]
        Returns an object representing the added content. 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 items that receive the additional content. Wildcards are permitted. If you specify multiple paths, use commas to separate the paths.

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

    -Value <Object[]>
        Specifies the content to be added. Type a quoted string, such as “This data is for internal use only”, or specify an object that contains content, such as the DateTime object that Get-Date generates.

        You cannot specify the contents of a file by typing its path, because the path is just a string, but you can use a Get-Content command to get the content and pass it to the Value parameter.

        Required?                    true
        Position?                    2
        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.Object
        You can pipe the objects to be added (the Value) to Add-Content.

OUTPUTS
    None or System.String
        When you use the Passthru parameter, Add-Content generates a System.String object representing the content. Otherwise, this cmdlet does not generate any output.

NOTES

        When you pipe an object to Add-Content, the object is converted to a string before it is added to the item. The object type determines the string format, but the format might be different than the default display of the object. To control the string format, use the formatting parameters of the sending cmdlet.

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

        The Add-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>Add-Content -Path *.txt -Exclude help* -Value “END”

    Description
    ———–
    This command adds “END” to all text files in the current directory, except for those with file names that begin with “help”.

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

    C:\PS>Add-Content -Path file1.log, file2.log -Value (Get-Date) -PassThru

    Description
    ———–
    This command adds the date to the end of the File1.log and File2.log files and then displays the date at the command line. The command uses the Get-Date cmdlet to get the date, and it uses the Value parameter to pass the date to Add-Content. The PassThru parameter passes an object representing the added content through the pipeline. Because there is no other cmdlet to receive the passed object, it is displayed at the command line.

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

    C:\PS>Add-Content -Path monthly.txt -Value (Get-Content c:\rec1\weekly.txt)

    Description
    ———–
    This command adds the contents of the Weekly.txt file to the end of the Monthly.txt file. It uses the Get-Content cmdlet to get the contents of the Weekly.txt file, and it uses the Value parameter to pass the content of weekly.txt to Add-Content. The parentheses ensure that the Get-Content command is complete before the Add-Content command begins.

    You can also copy the content of Weekly.txt to a Variable, such as $w, and then use the Value parameter to pass the Variable to Add-Content. In that case, the command would be “Add-Content -Path monthly.txt -Value $w”.

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

    C:\PS>Add-Content -Value (Get-Content test.log) -Path C:\tests\test134\logs\test134.log

    Description
    ———–
    This command creates a new directory and file and copies the content of an existing file to the newly created file.

    This command uses the Add-Content cmdlet to add the content. The value of the Value parameter is a Get-Content command that gets content from an existing file, Test.log.

    The value of the path parameter is a path that does not exist when the command runs. In this example, only the C:\Tests directories exist. The command creates the remaining directories and the Test134.log file.

    The Force parameter is not required for this command. Add-Content creates directories to complete a path even without the Force parameter.

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

Add-History

NAME
    Add-History

SYNOPSIS
    Appends entries to the session history.

SYNTAX
    Add-History [[-InputObject] <PSObject[]>] [-Passthru] [<CommonParameters>]

DESCRIPTION
    The Add-History cmdlet adds entries to the end of the session history, that is, the list of commands entered during the current session.

    You can use the Get-History cmdlet to get the commands and pass them to Add-History, or you can export the commands to a CSV or XML file, then import the commands, and pass the imported file to Add-History. You can use this cmdlet to add specific commands to the history or to create a single history file that includes commands from more than one session.

PARAMETERS
    -InputObject <PSObject[]>
        Adds the specified HistoryInfo object to the session history. You can use this parameter to submit a HistoryInfo object from Get-History, Import-Clixml, or Import-Csv to Add-History.

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

    -Passthru [<SwitchParameter>]
        Returns a history object for each history entry. By default, this cmdlet does not generate any output.

        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
    Microsoft.PowerShell.Commands.HistoryInfo
        You can pipe a HistoryInfo object to Add-History.

OUTPUTS
    None or Microsoft.PowerShell.Commands.HistoryInfo
        When you use the PassThru parameter, Add-History generates a HistoryInfo object. Otherwise, this cmdlet does not generate any output.

NOTES

        The session history is a list of the commands entered during the session along with the ID. The session history represents the order of execution, the status, and the start and end times of the command. As you enter each command, Windows PowerShell adds it to the history so that you can reuse it. For more information about the session history, see about_History.

        To specify the commands to add to the history, use the InputObject parameter. The Add-History command accepts only HistoryInfo objects, such as those generated for each command by Get-History. You cannot pass it a path and file name or a list of commands.

        You can use the -InputObject parameter to pass a file of HistoryInfo objects to Add-History. To do so, export the results of a Get-History command to a file by using Export-Csv or Export-Clixml and then import the file by using Import-Csv or Import-Clixml. You can then pass the file of imported HistoryInfo objects to Add-History through a pipeline or in a Variable. For more information, see the examples.

        The file of HistoryInfo objects that you pass to Add-History must include the type information, column headings, and all of the properties of the HistoryInfo objects. If you intend to pass the objects back to Add-History, do not use the NoTypeInformation parameter of Export-Csv and do not delete the type information, column headings, or any fields in the file.

        To edit the session history, export the session to a CSV or XML file, edit the file, import the file, and use Add-History to append it to the current session history.

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

    C:\PS>Get-History | Export-Csv c:\testing\history.csv

    C:\PS>Import-Csv history.csv | Add-History

    Description
    ———–
    These commands add the commands typed in one Windows PowerShell session to the history of a different Windows PowerShell session. The first command gets objects representing the commands in the history and exports them to the History.csv file. The second command is typed at the command line of a different session. It uses the Import-Csv cmdlet to import the objects in the History.csv file. The pipeline operator passes the objects to the Add-History cmdlet, which adds the objects representing the commands in the History.csv file to the current session history.

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

    C:\PS>Import-Clixml c:\temp\history.xml | Add-History -Passthru | ForEach-Object {Invoke-History}

    Description
    ———–
    This command imports commands from the History.xml file, adds them to the current session history, and then executes the commands in the combined history.

    The first command uses the Import-Clixml command to import a command history that was exported to the History.xml file. The pipeline operator (|) passes the commands to the Add-History parameter, which adds the commands to the current session history. The PassThru parameter passes the objects representing the added commands down the pipeline.

    The command then uses the ForEach-Object cmdlet to apply the Invoke-History command to each of the commands in the combined history. The Invoke-History command is formatted as a script block, which is enclosed in braces ({}) because ForEach-Object requires a script block even when there is only one command to apply.

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

    C:\PS>Get-History -id 5 -count 5 | Add-History

    Description
    ———–
    This command adds the first five commands in the history to the end of the history list. It uses the Get-History cmdlet to get the five commands ending in command 5. The pipeline operator (|) passes them to the Add-History cmdlet, which appends them to the current history. The Add-History command does not include any parameters, but Windows PowerShell associates the objects passed through the pipeline with the InputObject parameter.

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

    C:\PS>$a = Import-Csv c:\testing\history.csv

    C:\PS>Add-History -InputObject $a -Passthru

    Description
    ———–
    These commands add the commands in the History.csv file to the current session history. The first command uses the Import-Csv cmdlet to import the commands in the History.csv file and store its contents in the Variable $a. The second command uses the Add-History cmdlet to add the commands from History.csv to the current session history. It uses the InputObject parameter to specify the $a Variable and the PassThru parameter to generate an object to display at the command line. Without the PassThru parameter, Add-History does not generate any output to display.

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

    C:\PS>Add-History -InputObject (Import-Clixml c:\temp\history01.xml)

    Description
    ———–
    This command adds the commands in the History01.xml file to the current session history. It uses the InputObject parameter to pass the results of the command in parentheses to Add-History. The command in parentheses, which is executed first, imports the History01.xml file into Windows PowerShell. Add-History then adds the commands in the file to the session history.

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

Add-Computer

NAME
    Add-Computer

SYNOPSIS
    Add the local computer to a domain or workgroup.

SYNTAX
    Add-Computer [-DomainName] <string> [-Credential <PSCredential>] [-OUPath <string>] [-Server <string>] [-UnSecure] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Add-Computer [-WorkGroupName] <string> [-Credential <PSCredential>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Add-Computer cmdlet adds the local computer to a domain or workgroup, or moves it from one domain to another. It also creates a domain account if the computer is added to the domain without an account.

    You can use the parameters of this cmdlet to specify an organizational unit (OU) and domain controller or to perform an unsecure join.

    To get the results of the command, use the Verbose and PassThru parameters.

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.

        Required?                    false
        Position?                    named
        Default value                Current User Account Credentials
        Accept pipeline input?     false
        Accept wildcard characters? false

    -DomainName <string>
        Specifies a domain for the computer account. This parameter is required.

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

    -OUPath <string>
        Specifies an organizational unit (OU) for the domain account. Enter the full distinguished name of the OU. The default value is the default OU for machine objects in the domain.

        Required?                    false
        Position?                    named
        Default value                The default OU for machine objects for in the domain
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns the results of the command. By default, this cmdlet does not generate any output.

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

    -Server <string>
        Specifies the name of a domain controller that adds the computer to the domain. Enter the name in DomainName\ComputerName format. The default is the local computer.

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

    -UnSecure [<SwitchParameter>]
        Performs an unsecure join.

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

    -WorkGroupName <string>
        Specifies the name of a work group for the computer. If you omit this parameter, the computer is joined to a domain.

        Required?                    true
        Position?                    3
        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 Add-Computer.

OUTPUTS
    Microsoft.PowerShell.Commands.ComputerChangeInfo
        When you use the PassThru parameter, Add-Computer returns a ComputerChangeInfo object. Otherwise, this cmdlet does not generate any output.

NOTES

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

    C:\PS>Add-Computer -DomainName Domain01; Restart-Computer

    Description
    ———–
    These commands add the local computer to the Domain01 domain using the credentials of the current user.

    The first command adds the computer to the domain. The second command uses the Restart-Computer cmdlet to restart the computer, which completes the join operation. The semi-colon (;) separates the two commands.

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

    C:\PS>Add-Computer -workgroupname WORKGROUP-A

    Description
    ———–
    This command adds the local computer to the Workgroup-A workgroup.

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

    C:\PS>Add-Computer -DomainName Domain01 -Server Domain01\DC01 -PassThru -Verbose

    Description
    ———–
    This command adds the local computer to the Domain01 domain by using the Domain01\DC01 domain controller.

    The command uses the PassThru and Verbose parameters to get detailed information about the results of the command.

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

    C:\PS>Add-Computer -DomainName Domain02 -OUPath OU=testOU,DC=domain,DC=Domain,DC=com

    Description
    ———–
    This command adds the Server01 and Server02 computers to the Domain02 domain. It uses the OUPath command to specify the organization unit for the new accounts.

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

    C:\PS>Add-Computer -DomainName Domain02 -cred Domain02\Admin02 -PassThru

    Description
    ———–
    This command adds the local computer to the Domain02 domain by using the credentials of a domain administrator. The command uses the PassThru parameter to generate a brief report about the results of the command.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135194
    Checkpoint-Computer
    Remove-Computer
    Restart-Computer
    Restore-Computer
    Stop-Computer
    Test-Connection