PowerShell script to format data in Clipboard

I'd like to have a PowerShell script that reads the contents of my clipboard, parses and formats the data, then re-writes the clipboard so I can paste it in formatted.
The entire process is, copy data to clipboard, press hot-key shortcut to the script (ctrl+alt+q for example), script re-writes the clipboard, then I paste clipboard to destination.

I have data like this:
IP Address:
Mac Adress: ab-cd-12-34-56-78-90
User Name: Grace Jones
Domain: Forrest-1
OU: Sales and Engineering
Department: Sales
Manager: Gus Fring
Location: ABQ
Computer Name: AsdfNiner5er
The output I'd like only certain fields, in a certain order, not all fields are present with each copy, sometimes Mac-Address: isn't there, or IP: isn't populated. Basically you can not assume that any one of the lines above will be present and or not populated. "IP: x.x.x.x" may be missing entirely, or "Mac-Address: " might not be populated after the colon. When they are not present, and or not populated, I don't want to see them in the output either.
    Mac-Address: AB-CD-12-34-56-78-90
    User Name: Grace Jones
There are dozen's more input fields , and a few more the output, but that's the basic's. I figure "get-clipboard" and "set-clipboard" will do the trick nicely, I just have no idea about the parsing/formating.
LVL 38
Rich RumbleSecurity SamuraiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sam JacobsDirector of Technology Development, IPMCommented:

Save this as a .ps1 and assign a shortcut key to it:
$clipboard = @(Get-Clipboard)
$newCB = @()
foreach ($cb in $clipboard) {
   $aCB = @($cb.Split(":"))
   if ($aCB.Count -gt 1) {
	$newCB += $cb
Set-Clipboard -Value $newCB

Open in new window

Rich RumbleSecurity SamuraiAuthor Commented:
I like this so far, now for the formatting, I want to throw away most of the lines of input, and only have a select few put back into the clipboard (output).
And I still want what is on both sides of the colon, the entire line is fine, I just want to output certain lines, and in a certain order, rather than just alphabetically or numerically. I want to format the input into a certain output. Does that make sense? My example I don't think made that clear :) I see that now.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Your last example is wrong, input needs to have aaaa, not aaa ;-).
Because you want to have a certain order, we need to process in a loop:
# "keys" to keep, in desired order
$keys = 'eeee', 'aaaa', 'dddd'
# only keep interesting content having value
$content = get-clipboard | Select-string "^($($keys -join '|')):.+"
# now create sorted output
Set-Clipboard -value ($keys | foreach { $content | Select-String "^$_`:" } )

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Rich RumbleSecurity SamuraiAuthor Commented:
I am going to accept Qlemo's solution, I had to add a space before the colons in lines 4 and 6 to match my real data :)
My next question will build off of this one, running a command like "nslookup" when what's on the right of the colon for "IP Address : " is not null, and or when I want to open a another program based on what's on the right of the colon. I'll post that follow on Q here too.
Rich RumbleSecurity SamuraiAuthor Commented:
Rich RumbleSecurity SamuraiAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.