Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
[Cmdlet(VerbsCommon.Set, "Clipboard", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2109826")]
[Alias("scb")]
[OutputType(typeof(string))]
public class SetClipboardCommand : PSCmdlet
{
private readonly List<string> _contentList = new();
Expand All @@ -37,6 +38,12 @@ public class SetClipboardCommand : PSCmdlet
[Parameter]
public SwitchParameter Append { get; set; }

/// <summary>
/// Gets or sets if the values sent down the pipeline.
/// </summary>
[Parameter]
public SwitchParameter PassThru { get; set; }

/// <summary>
/// This method implements the BeginProcessing method for Set-Clipboard command.
/// </summary>
Expand All @@ -53,6 +60,11 @@ protected override void ProcessRecord()
if (Value != null)
{
_contentList.AddRange(Value);

if (PassThru)
{
WriteObject(Value);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,36 @@ Describe 'Clipboard cmdlet tests' -Tag CI {
$text | Set-Clipboard
Get-Clipboard -Raw | Should -BeNullOrEmpty
}

It 'Set-Clipboard should not return object' {
$result = 'hello' | Set-Clipboard
$result | Should -BeNullOrEmpty
}

It 'Set-Clipboard -PassThru returns single object with -Append = <Append>' -TestCases @(
@{ Append = $false }
@{ Append = $true }
){
param ($append)

$params = @{ PassThru = $true; Append = $append }

Set-Clipboard -Value 'world'
$result = 'hello' | Set-Clipboard @params
$result | Should -BeExactly 'hello'
}

It 'Set-Clipboard -PassThru returns multiple objects with -Append = <Append>' -TestCases @(
@{ Append = $false }
@{ Append = $true }
){
param ($append)

$params = @{ PassThru = $true; Append = $append }

Set-Clipboard -Value 'world'
$result = 'hello', 'world' | Set-Clipboard @params
$result | Should -BeExactly @('hello', 'world')
}
}
}