PowerShell: Set-Clipboard is missing -AsHtml

Prerequisites

Steps to reproduce

Set-Clipboard is missing -AsHtml in PS 7+

There is no known workaround or alternative for this incredibly useful feature.

Expected behavior

"<table><tr><td>Test</td><td>Test</td></tr></table>" | Set-Clipboard -AsHtml 

Should produce a table for any rich-text enabled Office application (Word, Outlook, OneNote) and maybe other applications that understand this.

Actual behavior

-AsHtml does not exist. Piping into |ConvertTo-Html does not work

Plain-text paste: <table><tr><td>Test</td><td>Test</td></tr></table>

Error details

Set-Clipboard: A parameter cannot be found that matches parameter name 'AsHtml'.

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

PowerShell 7 on Windows should have parity with Windows PowerShell 5.

I don’t understand why the PowerShell team won’t just take the necessary code from Windows Powershell and use it? Or is Microsoft just a name, and the project has nothing to do with the corporation?

There are two primary reasons (a) The code is something which cannot be open sourced, for whatever reason and (b) for some reason it was supported in .NET Framework but is not longer available in current .NET (and WHY? is a valid question there). Clipboard support went away in V6 for .NET related reasons, and came back in V7; I think in V7 it may be different code, or possibly just the subset of code which works cross platform . Sometimes teams in Microsoft do re-invent the wheel rather than using something from another group, but I don’t think is what is happening here.

I believe the reasoning on why this no longer exists has been answered. I would also encourage folks to publish a clipboard module to PSGallery whether it’s Windows only or, preferably, cross-platform. The built-in one as part of PS7 is intentionally limited to have it cross-platform.

CTRL+V into any Office application and get the effect

Tried to paste in wordpad. Then pasted in online Word. Now I understand what you meant. A strange feature for a console shell.

Indeed, a strange feature… but immensely useful! Going forward (if Powershell 7 will supersede version 5 at some point in the future), it would be good to retain this functionality.

CTRL+V into any Office application and get the effect

Tried to paste in wordpad. Then pasted in online Word. Now I understand what you meant. A strange feature for a console shell.

PowerShell 7 on Windows should have parity with Windows PowerShell 5.

I don’t understand why the PowerShell team won’t just take the necessary code from Windows Powershell and use it? Or is Microsoft just a name, and the project has nothing to do with the corporation?

@dkaszews, only Windows PowerShell does; the linked comment summarizes the non-plain-text parameters supported in Windows PowerShell that PS Core no longer supports. The question is if there’s a willingness to bring non-plain-text support back, and to what degree it can be implemented in a platform-agnostic fashion - having platform-specific parameters is generally undesirable.

As one guiding principle, platform specific parameters ARE undesirable
As a second principle, PowerShell 7 on Windows should have parity with Windows PowerShell 5.
And when these principles come into conflict they need to be dealt with on a case by case basis.

I have an open issue with Import-Excel where we do something which relies on the Windows PowerShell functionality, and it is a lot of trouble for a rarely used feature (a command to get a picture from an Excel workbook and save it) to work around it, So I would prefer “Parity with Windows PowerShell” to win. Other preferences are available, and valid 😃