This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM. Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
I cannot replicate that. I put something in the clipboard using notepad, then set a breakpoint in a script, start debugging.
While at the breakpoint, using notepad++ to paste the clipboard content. It is exactly what was copied in Notepad before.
Can you see if you can replicate the problem on your machine that way?
$Text = Get-Clipboard -Format Text
Write-Host "Text: $Text"
If we start the Script-File in a PowerShell session, it works as expected
Now, we set a Breakpoint on Line 2 in PowerShell Studio
In Notepad: we copy some Text into the Clipboard
In PowerShell Studio: we start the Debugger using F5
As soon as the breakpoint is hit, $Text is empty
Vers strange: if we now switch to the Notepad and paste the Clipboard, then the right Text is pasted into Notepad!
Therefore, it looks like Get-Clipboard does not work in PowerShell Studio
Additional Information:
In a normal PowerShell and in Sapien PowerShell Studio, we get this information about the Get-Clipboard command:
Set-Clipboard and Get-Clipboard are functions which only work in STA mode (Single Threaded Apartment).
Make sure to enable STA mode before running or debugging your script.
Interestingly enough, PowerShell spits out an error message when you use Set-Clipboard without STA mode:
ERROR: Set-Clipboard : Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has
ERROR: STAThreadAttribute marked on it.
ERROR: At C:\Users\Alex\Desktop\Files\Clipboard Test.ps1:22 char:1
ERROR: + Set-Clipboard -Value "This is a test"
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (:) [Set-Clipboard], ThreadStateException
ERROR: + FullyQualifiedErrorId : System.Threading.ThreadStateException,Microsoft.PowerShell.Commands.SetClipboardCommand
ERROR:
Text:
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.