Tag Archives: Encoding

Set-Content

NAME
    Set-Content

SYNOPSIS
    Writes or replaces the content in an item with new content.

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

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

DESCRIPTION
    The Set-Content cmdlet is a string-processing cmdlet that writes or replaces the content in the specified item, such as a file. Whereas the Add-Content cmdlet appends content to a file, Set-Content replaces the existing content. You can type the content in the command or send content through the pipeline to Set-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>]
        Allows the cmdlet to set the contents of a file, 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[]>
        Changes 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 item that will receive the 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 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 item that will receive the content. Wildcards are permitted.

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

    -Value <Object[]>
        Specifies the new content for the item.

        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 an object that contains the new value for the item to Set-Content.

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

NOTES

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

        Set-Content is designed for string processing. If you pipe non-string objects to Set-Content, it converts the object to a string before writing it. To write objects to files, use Out-File.

        The Set-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>Set-Content -Path C:\Test1\test*.txt -Value “Hello, World”

    Description
    ———–
    This command replaces the contents of all files in the Test1 directory that have names beginning with “test” with “Hello, World”. This example shows how to specify content by typing it in the command.

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

    C:\PS>Get-Date | Set-Content C:\Test1\date.csv

    Description
    ———–
    This command creates a comma-separated Variable-length (csv) file that contains only the current date and time. It uses the Get-Date cmdlet to get the current system date and time. The pipeline operator passes the result to Set-Content, which creates the file and writes the content.

    If the Test1 directory does not exist, the command fails, but if the file does not exist, the command will create it.

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

    C:\PS>(Get-Content Notice.txt) | ForEach-Object {$_ -replace “Warning”, “Caution”} | Set-Content Notice.txt

    Description
    ———–
    This command replaces all instances of “Warning” with “Caution” in the Notice.txt file.

    It uses the Get-Content cmdlet to get the content of Notice.txt. The pipeline operator sends the results to the ForEach-Object cmdlet, which applies the expression to each line of content in Get-Content. The expression uses the “$_” symbol to refer to the current item and the Replace parameter to specify the text to be replaced.

    Another pipeline operator sends the changed content to Set-Content which replaces the text in Notice.txt with the new content.

    The parentheses around the Get-Content command ensure that the Get operation is complete before the Set operation begins. Without them, the command will fail because the two Functions will be trying to access the same file.

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

Select-String

NAME
    Select-String

SYNOPSIS
    Finds text in strings and files.

SYNTAX
    Select-String [-Path] <string[]> [-Pattern] <string[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>] [-Encoding <string>] [-Exclude <string[]>] [-Include <string[]>] [-List] [-NotMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]

    Select-String -InputObject <psobject> [-Pattern] <string[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>] [-Encoding <string>] [-Exclude <string[]>] [-Include <string[]>] [-List] [-NotMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]

DESCRIPTION
    The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows.

    Select-String is based on lines of text. By default, Select-String finds the first match in each line and, for each match, it displays the file name, line number, and all text in the line containing the match.

    However, you can direct it to detect multiple matches per line, display text before and after the match, or display only a Boolean value (true or false) that indicates whether a match is found.

    Select-String uses regular expression matching, but it can also perform a simple match that searches the input for the text that you specify.

    Select-String can display all of the text matches or stop after the first match in each input file. It can also display all text that does not match the specified pattern.

    You can also specify that Select-String should expect a particular character encoding, such as when you are searching files of Unicode text.

PARAMETERS
    -AllMatches [<SwitchParameter>]
        Searches for more than one match in each line of text. Without this parameter, Select-String finds only the first match in each line of text.

        When Select-String finds more than one match in a line of text, it still emits only one MatchInfo object for the line, but the Matches property of the object contains all of the matches.

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

    -CaseSensitive [<SwitchParameter>]
        Makes matches case-sensitive. By default, matches are not case-sensitive.

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

    -Context <Int32[]>
        Captures the specified number of lines before and after the line with the match. This allows you to view the match in context.

        If you enter one number as the value of this parameter, that number determines the number of lines captured before and after the match. If you enter two numbers as the value, the first number determines the number of lines before the match and the second number determines the number of lines after the match.

        In the default display, lines with a match are indicated by a right angle bracket (ASCII 62) in the first column of the display. Unmarked lines are the context.

        This parameter does not change the number of objects generated by Select-String. Select-String generates one MatchInfo (Microsoft.PowerShell.Commands.MatchInfo) object for each match. The context is stored as an array of strings in the Context property of the object.

        When you pipe the output of a Select-String command to another Select-String command, the receiving command searches only the text in the matched line (the value of the Line property of the MatchInfo object), not the text in the context lines. As a result, the Context parameter is not valid on the receiving Select-String command.

        When the context includes a match, the MatchInfo object for each match includes all of the context lines, but the overlapping lines appear only once in the display.

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

    -Encoding <string>
        Specifies the character encoding that Select-String should assume when searching the file. The default is UTF8.

        Valid values are “UTF7”, “UTF8”, “UTF32”, “ASCII”, “Unicode”, “BigEndianUnicode”, “Default”, and “OEM”. “Default” is the encoding of the system’s current ANSI code page. “OEM” is the current original equipment manufacturer code page identifier for the operating system.

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

    -Exclude <string[]>
        Exclude 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

    -Include <string[]>
        Include 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

    -InputObject <psobject>
        Specifies the text to be searched. Enter a Variable that contains the text, or type a command or expression that gets the text.

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

    -List [<SwitchParameter>]
        Returns only the first match in each input file. By default, Select-String returns a MatchInfo object for each match it finds.

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

    -NotMatch [<SwitchParameter>]
        Finds text that does not match the specified pattern.

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

    -Path <string[]>
        Specifies the path to the files to be searched. Wildcards are permitted. The default location is the local directory.

        Specify files in the directory, such as “log1.txt”, “*.doc”, or “*.*”. If you specify only a directory, the command fails.

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

    -Pattern <string[]>
        Specifies the text to find. Type a string or regular expression. If you type a string, use the SimpleMatch parameter.

        To learn about regular expressions, see about_regular_expressions.

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

    -Quiet [<SwitchParameter>]
        Returns a Boolean value (true or false), instead of a MatchInfo object. The value is “true” if the pattern is found; otherwise, the value is “false”.

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

    -SimpleMatch [<SwitchParameter>]
        Uses a simple match rather than a regular expression match. In a simple match, Select-String searches the input for the text in the Pattern parameter. It does not interpret the value of the Pattern parameter as a regular expression statement.

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

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

INPUTS
    System.Management.Automation.PSObject
        You can pipe any object that has a ToString method to Select-String.

OUTPUTS
    Microsoft.PowerShell.Commands.MatchInfo or System.Boolean
        By default, the output is a set of MatchInfo objects, one for each match found. If you use the Quiet parameter, the output is a Boolean value indicating whether the pattern was found.

NOTES

        Select-String is like the Grep command in UNIX and the FindStr command in Windows.

        To use Select-String, type the text that you want to find as the value of the Pattern parameter.

        To specify the text to be searched, do the following:

        — Type the text in a quoted string, and then pipe it to Select-String.
        — Store a text string in a Variable, and then specify the Variable as the value of the InputObject parameter.
        — If the text is stored in files, use the Path parameter to specify the path to the files.

        By default, Select-String interprets the value of the Pattern parameter as a regular expression. (For more information, see about_regular_expressions.) However, you can use the SimpleMatch parameter to override the regular expression matching. The SimpleMatch parameter finds instances of the value of the Pattern parameter in the input.

        The default output of Select-String is a MatchInfo object, which includes detailed information about the matches. The information in the object is useful when you are searching for text in files, because MatchInfo objects have properties such as Filename and Line. When the input is not from the file, the value of these parameters is “InputStream”.

        If you do not need the information in the MatchInfo object, use the Quiet parameter, which returns a Boolean value (true or false) to indicate whether it found a match, instead of a MatchInfo object.

        When matching phrases, Select-String uses the current that is set for the system. To find the current culture, use the Get-Culture cmdlet.

        To find the properties of a MatchInfo object, type the following:

        Select-String -path test.txt -Pattern “test” | Get-Member | Format-List -property *

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

    C:\PS>”Hello”,”HELLO” | Select-String -Pattern “HELLO” -CaseSensitive

    Description
    ———–
    This command performs a case-sensitive match of the text that was piped to the Select-String command.

    As a result, Select-String finds only “HELLO”, because “Hello” does not match.

    Because each of the quoted strings is treated as a line, without the CaseSensitive parameter, Select-String would recognize both of the strings as matches.

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

    C:\PS>Select-String -path *.xml -Pattern “the the”

    Description
    ———–
    This command searches through all files with the .xml file name extension in the current directory and displays the lines in those files that include the string “the the”.

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

    C:\PS>Select-String -path $pshome\en-US\*.txt -Pattern “@”

    Description
    ———–
    This command searches the Windows PowerShell conceptual Help files (about_*.txt) for information about the use of the at sign (@).

    To indicate the path, this command uses the value of the $pshome automatic Variable, which stores the path to the Windows PowerShell installation directory. In this example, the command searches the en-US subdirectory, which contains the English (US) language Help files for Windows PowerShell.

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

    C:\PS>function search-help
    {
        $pshelp = “$pshome\es\about_*.txt”, “$pshome\en-US\*dll-help.xml”
        Select-String -path $pshelp -Pattern $args[0]
    }

    Description
    ———–
    This simple Function uses the Select-String cmdlet to search the Windows PowerShell Help files for a particular string. In this example, the Function searches the “en-US” subdirectory for English-United States language files.

    To use the Function to find a string, such as “psdrive”, type “search-help psdrive”.

    To use this Function in any Windows PowerShell console, change the path to point to the Windows PowerShell Help files on your system, and then paste the Function in your Windows PowerShell profile.

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

    C:\PS>$events = Get-Eventlog -logname application -newest 100

    C:\PS> $events | Select-String -InputObject {$_.message} -Pattern “failed”

    Description
    ———–
    This example searches for the string “failed” in the 100 newest events in the Application log in Event Viewer.

    The first command uses the Get-EventLog cmdlet to get the 100 most recent events from the Application event log. Then it stores the events in the $events Variable.

    The second command uses a pipeline operator (|) to send the objects in the $events Variable to Select-String. It uses the InputObject parameter to represent the input from the $events Variable. The value of the InputObject parameter is the Message property of each object as it travels through the pipeline. The current object is represented by the $_ symbol.

    As each event arrives in the pipeline, Select-String searches the value of its Message property for the “failed” string, and then displays any lines that include a match.

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

    C:\PS>Get-ChildItem c:\windows\system32\* -Include *.txt -recurse |
    Select-String -Pattern “Microsoft” -CaseSensitive

    Description
    ———–
    This command examines all files in the subdirectories of C:\Windows\System32 with the .txt file name extension and searches for the string “Microsoft”. The CaseSensitive parameter indicates that the “M” in “Microsoft” must be capitalized and that the rest of the characters must be lowercase for Select-String to find a match.

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

    C:\PS>Select-String -path process.txt -Pattern idle, svchost -NotMatch

    Description
    ———–
    This command finds lines of text in the Process.txt file that do not include the words “idle” or “svchost”.

    ————————– EXAMPLE 8 ————————–

    C:\PS>$f = Select-String -path audit.log -Pattern “logon failed” -Context 2, 3

    C:\PS> $f.count

    C:\PS> ($f)[0].context | Format-List

    Description
    ———–
    The first command searches the Audit.Log file for the phrase “logon failed.” It uses the Context parameter to capture 2 lines before the match and 3 lines after the match.

    The second command uses the Count property of object arrays to display the number of matches found, in this case, 2.

    The third command displays the lines stored in the Context property of the first MatchInfo object. It uses array notation to indicate the first match (match 0 in a zero-based array), and it uses the Format-List cmdlet to display the value of the Context property as a list.

    The output consists of two MatchInfo objects, one for each match detected. The context lines are stored in the Context property of the MatchInfo object.

    ————————– EXAMPLE 9 ————————–

    C:\PS>$a = Get-ChildItem $pshome\en-us\about*.help.txt | Select-String -Pattern transcript

    C:\PS> $b = Get-ChildItem $pshome\en-us\about*.help.txt | Select-String -Pattern transcript -AllMatches

    C:\PS> $a
    C:\Windows\system32\WindowsPowerShell\v1.0\en-us\about_Pssnapins.help.txt:39:     Start-Transcript and Stop-Transcript.

    C:\PS> $b
    C:\Windows\system32\WindowsPowerShell\v1.0\en-us\about_Pssnapins.help.txt:39:     Start-Transcript and Stop-Transcript.

    C:\PS>> $a.matches
    Groups : {Transcript}
    Success : True
    Captures : {Transcript}
    Index    : 13
    Length : 10
    Value    : Transcript

    C:\PS> $b.matches
    Groups : {Transcript}
    Success : True
    Captures : {Transcript}
    Index    : 13
    Length : 10
    Value    : Transcript

    Groups : {Transcript}
    Success : True
    Captures : {Transcript}
    Index    : 33
    Length : 10
    Value    : Transcript

    Description
    ———–
    This example demonstrates the effect of the AllMatches parameter of Select-String. AllMatches finds all pattern matches in a line, instead of just finding the first match in each line.

    The first command in the example searches the Windows PowerShell conceptual Help files (“about” Help) for instances of the word “transcript”. The second command is identical, except that it uses the AllMatches parameter.

    The output of the first command is saved in the $a Variable. The output of the second command is saved in the $b Variable.

    When you display the value of the Variables, the default display is identical, as shown in the example output.

    However, the fifth and sixth commands display the value of the Matches property of each object. The Matches property of the first command contains just one match (that is, one System.Text.RegularExpressions.Match object), whereas the Matches property of the second command contains objects for both of the matches in the line.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113388
    about_Comparison_Operators
    about_regular_expressions

Send-MailMessage

NAME
    Send-MailMessage

SYNOPSIS
    Sends an e-mail message.

SYNTAX
    Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]

DESCRIPTION
    The Send-MailMessage cmdlet sends an e-mail message from within Windows PowerShell.

PARAMETERS
    -Attachments <string[]>
        Specifies the path and file names of files to be attached to the e-mail message. You can use this parameter or pipe the paths and file names to Send-MailMessage.

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

    -Bcc <string[]>
        Specifies the e-mail addresses that receive a copy of the mail but are not listed as recipients of the message. Enter names (optional) and the e-mail address, such as “Name <someone@example.com>”.

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

    -Body <string>
        Specifies the body (content) of the e-mail message.

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

    -BodyAsHtml [<SwitchParameter>]
        Indicates that the value of the Body parameter contains HTML.

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

    -Cc <string[]>
        Specifies the e-mail addresses to which a carbon copy (CC) of the e-mail message is sent. Enter names (optional) and the e-mail address, such as “Name <someone@example.com>”.

        Required?                    false
        Position?                    named
        Default value                None
        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” or “Domain01\User01”. Or, enter a PSCredential object, such as one from the Get-Credential cmdlet.

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

    -DeliveryNotificationOption <DeliveryNotificationOptions>
        Specifies the delivery notification options for the e-mail message. You can specify multiple values. “None” is the default value. The Alias for this parameter is “dno”.

        The delivery notifications are sent in an e-mail message to the address specified in the value of the To parameter.

        Valid values are:

         — None: No notification.
         — OnSuccess: Notify if the delivery is successful.
         — OnFailure: Notify if the delivery is unsuccessful.
         — Delay: Notify if the delivery is delayed.
         — Never: Never notify.

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

    -Encoding <Encoding>
        Specifies the encoding used for the body and subject. Valid values are ASCII, UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, Default, and OEM. ASCII is the default.

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

    -From <string>
        Specifies the address from which the mail is sent. Enter a name (optional) and e-mail address, such as “Name <someone@example.com>”. This parameter is required.

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

    -Priority <MailPriority>
        Specifies the priority of the e-mail message. The valid values for this are Normal, High, and Low. Normal is the default.

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

    -SmtpServer <string>
        Specifies the name of the SMTP server that sends the e-mail message.

        The default value is the value of the $PSEmailServer preference Variable. If the preference Variable is not set and this parameter is omitted, the command fails.

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

    -Subject <string>
        Specifies the subject of the e-mail message. This parameter is required.

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

    -To <string[]>
        Specifies the addresses to which the mail is sent. Enter names (optional) and the e-mail address, such as “Name <someone@example.com>”. This parameter is required.

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

    -UseSsl [<SwitchParameter>]
        Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail. By default, SSL is not used.

        Required?                    false
        Position?                    named
        Default value                False
        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 the path and file names of attachments to Send-MailMessage.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

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

    C:\PS>Send-MailMessage -To “User01 <user01@example.com>” -From “User02 <user02@example.com>” -Subject “Test mail”

    Description
    ———–
    This command sends an e-mail message from User01 to User02.

    The mail message has a subject, which is required, but it does not have a body, which is optional. Also, because the SmtpServer parameter is not specified, Send-MailMessage uses the value of the $PSEmailServer preference Variable for the SMTP server.

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

    C:\PS>Send-MailMessage -From “User01 <user01@example.com>” -To “User02 <user02@example.com>”, “User03 <user03@example.com>” -Subject “Sending the Attachment” -Body “Forgot to send the attachment. Sending now.” -Attachment “data.csv” -Priority High -dno onSuccess, onFailure -SmtpServer smtp.fabrikam.com

    Description
    ———–
    This command sends an e-mail message with an attachment from User01 to two other users.

    It specifies a priority value of “High” and requests a delivery notification by e-mail when the e-mail messages are delivered or when they fail.

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

    C:\PS>Send-MailMessage -To “User01 <user01@example.com>” -From “ITGroup <itdept@example.com>” -Cc “User02 <user02@example.com>” -Bcc ITMgr <itmgr@example.com> -Subject “Don’t forget today’s meeting!” -Credential domain01\admin01 -UseSsl

    Description
    ———–
    This command sends an e-mail message from User01 to the ITGroup mailing list with a copy (CC) to User02 and a blind carbon copy (BCC) to the IT manager (ITMgr).

    The command uses the credentials of a domain administrator and the UseSSL parameter.

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

Out-File

NAME
    Out-File

SYNOPSIS
    Sends output to a file.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

OUTPUTS
    None
        Out-File does not generate any output.

NOTES

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

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

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

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

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

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

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

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

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

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

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

    C:\PS>$a = Get-Process

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

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

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

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

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

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

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

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

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

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

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

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

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

Get-Content

NAME
    Get-Content

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

INPUTS
    None
        You cannot pipe input to Get-Content.

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

NOTES

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

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

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

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

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

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

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

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

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

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

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

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

Export-PSSession

NAME
    Export-PSSession

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        For more information, see about_PSSnapins and Import-Module.

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

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

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

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

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

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

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

INPUTS
    None
        You cannot pipe objects to Export-PSSession.

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

NOTES

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    C:\PS> Remove-PSSession $s

    C:\PS> Import-Module TestCmdlets

    C:\PS> Get-Help test*

    C:\PS> test-files

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    C:\PS> Remove-PSSession $s

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

    C:\PS> Import-Module Server01

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

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

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

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

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

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

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

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

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

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

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

Export-Clixml

NAME
    Export-Clixml

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

NOTES

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

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

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

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

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

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

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

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

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

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

Export-Csv

NAME
    Export-Csv

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

NOTES

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

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

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

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

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

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

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

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

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

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

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

    # In processes.csv

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

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

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

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

    # In processes.csv

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

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

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

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

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

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

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

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

    # In processes.csv

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

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

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

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