MSH>Out-Clipboard "Hello, World"
Begin Processing...
Processing Record...
Setting String
End Processing...
MSH>"Hello, World" | Out-Clipboard
Begin Processing...
Processing Record...
Setting MshObject
End Processing...
using System;
using System.Threading;
using System.Windows.Forms;
using System.ComponentModel;
using System.Management.Automation;
using System.Collections.Generic;
using System.Text;
namespace snapins
{
[RunInstaller(true)]
public class OutClipboardSnapin : System.Management.Automation.MshSnapIn
{
public OutClipboardSnapin() : base()
{
}
public override string Name
{
get { return "OutClipboardSnapin"; }
}
public override string Vendor
{
get { return "DontBotherMeWithSpam"; }
}
public override string Description
{
get { return "This snapin receives piped output into Clipboard"; }
}
}
[Cmdlet("Out", "Clipboard")]
public class OutClipboardCommand : Cmdlet
{
private Thread t;
private object inputData;
/// <summary>
/// Input data to send to clipboard
/// </summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline=true)]
public object InputData
{
get { return inputData; }
set { inputData = value; }
}
protected override void BeginProcessing()
{
t = new Thread(new ThreadStart(SetObject));
t.SetApartmentState(ApartmentState.STA);
WriteObject("Begin Processing...");
}
protected override void ProcessRecord()
{
WriteObject("Processing Record...");
WriteObject("Setting " + this.InputData.GetType().Name);
t.Start();
}
protected override void EndProcessing()
{
t.Join();
WriteObject("End Processing...");
}
private void SetObject()
{
if (this.InputData.GetType() == typeof(string))
{
Clipboard.SetText(this.InputData.ToString());
}
else
{
Clipboard.SetDataObject(this.InputData);
}
}
}
}
Experimenting with a different format of blogs...