Tag Archives: WhatIf

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