external help file | Module Name | online version | schema |
---|---|---|---|
PSScriptTools-help.xml |
PSScriptTools |
2.0.0 |
Send command output to the pipeline and clipboard.
Out-Copy [-InputObject] <Object> [-Width <Int32>] [-CommandOnly] [-Ansi] [<CommonParameters>]
This command is intended for writers and those who need to document with PowerShell. You can pipe any command to this function and you will get the regular output in your PowerShell session. Simultaneously, a copy of the output will be sent to the Windows clipboard. The copied output will include a prompt constructed from the current location unless you use the CommandOnly parameter.
NOTE: You can only capture what is written to the Success pipeline. This command will not copy any other streams such as Verbose, Warning, or Error.
PS C:\> Get-Process | Sort WS -Descending | Select-First 5 | Out-Copy
This will execute your expression and write the output to the pipeline. The output plus the command except for the pipe to Out-Copy will be copied to the clipboard. This example is using the Select-First function from the PSScriptTools module.
PS C:\> Get-ChildItem *.ps1 | Out-File c:\work\ps.txt | Out-Copy
Even if your command doesn't write anything to the pipeline, Out-Copy will still capture a prompt and PowerShell expression.
PS C:\> Get-CimInstance -class win32_logicaldisk -filter "drivetype = 3" |
Out-Copy -commandonly
This will run the Get-CimInstance command and write results to the pipeline. But the only text that will be copied to the clipboard is:
Get-CimInstance -class win32_logicaldisk -filter "drivetype = 3"
PS C:\> Get-Process | Sort WS -Descending | Select-Object -first 5 | Out-Copy -ansi
Copy the command and output including any ANSI formatting which you might get in PowerShell 7.
This is the piped in command.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Specifies the number of characters in each line of output. Any additional characters are truncated, not wrapped.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 80
Accept pipeline input: False
Accept wildcard characters: False
Only copy the executed command, without references to Out-Copy, to the Windows clipboard.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Include any Ansi formatting. The default behavior is to capture plain text.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Learn more about PowerShell:http://jdhitsolutions.com/blog/essential-powershell-resources/