{"id":4489,"date":"2015-08-12T11:04:55","date_gmt":"2015-08-12T15:04:55","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=4489"},"modified":"2015-08-12T11:13:02","modified_gmt":"2015-08-12T15:13:02","slug":"teeing-up-to-the-clipboard","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/","title":{"rendered":"Teeing Up to the Clipboard"},"content":{"rendered":"<p>Because I spend a great part of my day creating PowerShell related content, I often need to copy command output from a PowerShell session. The quick and dirty solution is to pipe my expression to the Clip.exe command line utility.<\/p>\n<pre><code>get-service | where { $_.status -eq 'running'} | clip<\/code><\/pre>\n<p style=\"text-align: justify;\">This works in both the console and PowerShell ISE. But there are situations where I'd like to see the result so that I know it is worth pasting into whatever I'm working on. In other words I want to send the results of the command to the pipeline and the clipboard at the same time. PowerShell can already do something similar with the <a title=\"Read online help for Tee-Object\" href=\"http:\/\/go.microsoft.com\/fwlink\/p\/?linkid=294019\" target=\"_blank\">Tee-Object<\/a> cmdlet. With that cmdlet you can tee output to a variable or a file. So I decided to build a wrapper around Tee-Object and add functionality to send tee output to the clipboard.<\/p>\n<p style=\"text-align: justify;\">I created a copy of Tee-Object and started modifying. I didn't want to reverse-engineer the cmdlet. I simply wanted to add a new parameter. In some ways, my new command is like a proxy function.<\/p>\n<pre class=\"lang:ps decode:true \">#requires -version 4.0\r\n\r\n\r\n&lt;#\r\nThis is a copy of:\r\n\r\nCommandType Name       ModuleName                  \r\n----------- ----       ----------                  \r\nCmdlet      Tee-Object Microsoft.PowerShell.Utility\r\n\r\nCreated: 8\/12\/2015\r\nAuthor : Jeff Hicks @JeffHicks\r\n\r\n  ****************************************************************\r\n  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *\r\n  * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK.  IF   *\r\n  * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *\r\n  * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.             *\r\n  ****************************************************************\r\n#&gt;\r\n\r\n\r\nFunction Tee-MyObject {\r\n&lt;#\r\n\r\n.SYNOPSIS\r\n\r\nSaves command output in a file, variable or Windows Clipboard and also sends it down the pipeline.\r\n\r\n\r\n.DESCRIPTION\r\n\r\nThe cmdlet redirects output, that is, it sends the output of a command in two directions (like the letter \"T\"). It stores the output in a file or variable and also sends it down the pipeline. If  is the last command in the pipeline, the command output is displayed at the prompt.\r\n\r\nThis command is a modified version of Tee-Object.\r\n.PARAMETER Clipboard\r\nCopy the output to the Windows clipboard\r\n\r\n.PARAMETER Append\r\nAppends the output to the specified file. Without this parameter, the new content replaces any existing content in the file without warning.\r\n\r\nThis parameter is introduced in Windows PowerShell 3.0.\r\n\r\n.PARAMETER FilePath\r\nSaves the object in the specified file. Wildcard characters are permitted, but must resolve to a single file.\r\n\r\n.PARAMETER InputObject\r\nSpecifies the object to be saved and displayed. Enter a variable that contains the objects or type a command or expression that gets the objects. You can also pipe an object to .\r\n\r\nWhen you use the InputObject parameter with , instead of piping command results to , the InputObject value\u2014even if the value is a collection that is the result of a command, such as \u2013InputObject (Get-Process)\u2014is treated as a single object. Because InputObject cannot return individual properties from an array or collection of objects, it is recommended that if you use  to perform operations on a collection of objects for those objects that have specific values in defined properties, you use  in the pipeline, as shown in the examples in this topic.\r\n\r\n.PARAMETER Variable\r\nSaves the object in the specified variable. Enter a variable name without the preceding dollar sign ($).\r\n\r\n.PARAMETER LiteralPath\r\nSaves the object in the specified file. Unlike FilePath, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.\r\n\r\n\r\n.EXAMPLE\r\nPS C:\\&gt; Get-Eventlog -list | Tee-MyObject -clipboard\r\n\r\n\r\n  Max(K) Retain OverflowAction        Entries Log \r\n  ------ ------ --------------        ------- --- \r\n  20,480      0 OverwriteAsNeeded      30,245 Application\r\n  20,480      0 OverwriteAsNeeded           0 HardwareEvents \r\n     512      7 OverwriteOlder              0 Internet Explorer\r\n  20,480      0 OverwriteAsNeeded           0 Key Management Service\r\n     128      0 OverwriteAsNeeded       1,590 OAlerts               \r\n  32,768      0 OverwriteAsNeeded      49,749 Security \r\n  20,480      0 OverwriteAsNeeded      33,273 System \r\n  15,360      0 OverwriteAsNeeded      11,442 Windows PowerShell\r\n\r\nDisplay eventlog information and also copy it to the Windows clipboard.\r\n\r\n.EXAMPLE\r\n\r\nPS C:\\&gt; get-process | Tee-MyObject -filepath C:\\Test1\\testfile2.txt\r\n\r\nHandles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)    Id ProcessName\r\n-------  ------    -----      ----- -----   ------    -- -----------\r\n83       4     2300       4520    39     0.30    4032 00THotkey\r\n272      6     1400       3944    34     0.06    3088 alg\r\n81       3      804       3284    21     2.45     148 ApntEx\r\n81       4     2008       5808    38     0.75    3684 Apoint\r\n...\r\nThis command gets a list of the processes running on the computer and sends the result to a file. Because a second path is not specified, the processes are also displayed in the console.\r\n\r\n.EXAMPLE\r\n\r\nPS C:\\&gt; get-process notepad | Tee-MyObject -variable proc | select-object processname,handles\r\n\r\nProcessName                              Handles\r\n-----------                              -------\r\nnotepad                                  43\r\nnotepad                                  37\r\nnotepad                                  38\r\nnotepad                                  38\r\nThis command gets a list of the processes running on the computer and sends the result to a variable named \"proc\". It then pipes the resulting objects along to Select-Object, which selects the ProcessName and Handles property. Note that the $proc variable includes the default information returned by Get-Process.\r\n\r\n.EXAMPLE\r\n\r\nPS C:\\&gt;get-childitem \u2013path D: \u2013file \u2013system \u2013recurse | Tee-MyObject \u2013file c:\\test\\AllSystemFiles.txt \u2013append | out-file c:\\test\\NewSystemFiles.txt\r\nThis command saves a list of system files in a two log files, a cumulative file and a current file.\r\nThe command uses the Get-ChildItem cmdlet to do a recursive search for system files on the D: drive. A pipeline operator (|) sends the list to , which appends the list to the AllSystemFiles.txt file and passes the list down the pipeline to the Out-File cmdlet, which saves the list in the NewSystemFiles.txt file.\r\n\r\n.NOTES\r\n\r\nYou can also use the Out-File cmdlet or the redirection operator, both of which save the output in a file but do not send it down the pipeline.\r\n uses Unicode encoding when it writes to files. As a result, the output might not be formatted properly in files with a different encoding. To specify the encoding, use the Out-File cmdlet.\r\n\r\nLearn more about PowerShell:\r\n<blockquote class=\"wp-embedded-content\" data-secret=\"WZyY63kQFd\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/essential-powershell-resources\/\">Essential PowerShell Learning Resources<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Essential PowerShell Learning Resources&#8221; &#8212; The Lonely Administrator\" src=\"https:\/\/jdhitsolutions.com\/blog\/essential-powershell-resources\/embed\/#?secret=8SwFElbY4W#?secret=WZyY63kQFd\" data-secret=\"WZyY63kQFd\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\r\n\r\n.INPUTS\r\nSystem.Management.Automation.PSObject\r\n\r\n\r\n.OUTPUTS\r\nSystem.Management.Automation.PSObject\r\n\r\n.LINK\r\nTee-Object\r\nSelect-Object\r\nabout_Redirection\r\n\r\n#&gt;\r\n[CmdletBinding(DefaultParameterSetName='File')]\r\nParam(\r\n\r\n    [Parameter(ValueFromPipeline=$true)]\r\n    [psobject]$InputObject,\r\n\r\n    [Parameter(ParameterSetName='File', Mandatory=$true, Position=0)]\r\n    [string]$FilePath,\r\n\r\n    [Parameter(ParameterSetName='LiteralFile', Mandatory=$true)]\r\n    [Alias('PSPath')]\r\n    [string]$LiteralPath,\r\n\r\n    [Parameter(ParameterSetName='File')]\r\n    [switch]$Append,\r\n\r\n    [Parameter(ParameterSetName='Variable', Mandatory=$true)]\r\n    [string]$Variable,\r\n\r\n    [Parameter(ParameterSetName='Clip')]\r\n    [Switch]$Clipboard\r\n)\r\n\r\nBegin {\r\n\r\n    Write-Verbose \"Starting $($MyInvocation.Mycommand)\"\r\n    Write-Verbose \"Using parameter set $($PSCmdlet.ParameterSetName)\"  \r\n\r\n    #initialize array to hold all input. We will process it later\r\n    #with Tee-Object\r\n    $data=@()\r\n} #begin\r\n\r\nProcess {\r\n    #add each piped in object to the array\r\n    $data+= $InputObject\r\n} #process\r\n\r\nEnd {\r\n    Write-Verbose \"Processing $($data.count) input items\"\r\n    #run results through Tee-Object or Clipboard\r\n    #remove Clipboard from PSBoundParameters\r\n    if ($Clipboard) {\r\n        #copy to clipboard with extra spaces removed\r\n        $text = ($data | Out-String).Trim() -replace \"\\s+`n\",\"`n\"\r\n        #make sure type is loaded\r\n        Write-Verbose \"Adding necessary .NET assembly\"\r\n        Add-Type -AssemblyName system.windows.forms\r\n        [System.Windows.Forms.Clipboard]::SetText( $text )\r\n        #write data to the pipeline\r\n        $data\r\n    }\r\n    Else {\r\n        $PSBoundParameters.InputObject = $data\r\n        Write-Verbose \"Using PSBoundparameters $($PSBoundParameters | Out-String)\"\r\n        Tee-Object @PSBoundParameters\r\n\r\n        if ($Variable) {\r\n            #raise the scope to the parent or calling level to persist it\r\n            Write-Verbose \"Adjusting variable scope\"\r\n            #create a copy of the variable in the parent scope\r\n            New-Variable -Name $Variable -Value $(Get-Variable -name $variable).value -Scope 1 -Force\r\n        }\r\n    }\r\n\r\n    Write-Verbose \"Ending $($MyInvocation.Mycommand)\"\r\n\r\n} #end\r\n\r\n} #end function Tee-Object\r\n\r\n#define an optional alias\r\nSet-Alias -Name tmo -Value Tee-MyObject<\/pre>\n<p style=\"text-align: justify;\">I use Tee-MyObject much the same way as Tee-Object, even with the same parameters. Those are splatted through $PSBoundParameters. There are a few items I want to point out, more as a matter of scripting technique than anything.<\/p>\n<p style=\"text-align: justify;\">First, because my function is wrapping around Tee-Object, which typically has input piped to it, I needed to temporarily store piped in objects to my function. That's why I initialize a variable, $data and add each input object to it. After everything has been piped to my function, I can pass the data to Tee-Object, assuming I'm using one of its parameters.<\/p>\n<pre><code>$PSBoundParameters.InputObject = $data\r\nWrite-Verbose \"Using PSBoundparameters $($PSBoundParameters | Out-String)\"\r\nTee-Object @PSBoundParameters<\/code><\/pre>\n<p style=\"text-align: justify;\">However, because I am running Tee-Object inside of a function, scope becomes an issue. When I use the \u2013Variable parameter, Tee-Object creates the variable with no problem. But when the function ends, the variable is destroyed. My solution is to create a new copy of the variable and specify the parent scope.<\/p>\n<pre><code>if ($Variable) {\r\n            #raise the scope to the parent or calling level to persist it\r\n            Write-Verbose \"Adjusting variable scope\"\r\n            #create a copy of the variable in the parent scope\r\n            New-Variable -Name $Variable -Value $(Get-Variable -name $variable).value -Scope 1 -Force\r\n        }<\/code><\/pre>\n<p style=\"text-align: justify;\">I needed this \"tricks\" in order to pass on full functionality between my wrapper function and Tee-Object.<\/p>\n<p style=\"text-align: justify;\">For the clipboard part, I originally used code to simply pipe data to Clip.exe. However, this can temporary flash a console window and depending on the command I also end up with lots of extra white space at the end of each line. So I decided to use the .NET framework to add content to the clipboard. The tricky part was converting the output to text and cleaning it up. I ended up using the Trim() method to remove leading and trailing spaces after piping the data to <a title=\"Read online help for Out-String\" href=\"http:\/\/go.microsoft.com\/fwlink\/p\/?linkid=293999\" target=\"_blank\">Out-String<\/a>. This leaves me with one long string. To clean up the extra space at the end of some lines, I use the \u2013Replace operator to find anything that matches a bunch of spaces followed by the new line marker and replace it with just the new line marker. This has the effect of trimming away all those spaces.<\/p>\n<pre><code>$text = ($data | Out-String).Trim() -replace \"\\s+`n\",\"`n\"<\/code><\/pre>\n<p style=\"text-align: justify;\">And that's it! My version even has a modified copy of the help for Tee-Object.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png\" alt=\"\" \/><span style=\"color: #44546a; font-size: 9pt;\"><em>Modified help<\/em><\/span><\/p>\n<p style=\"text-align: justify;\">I can use my command in place of Tee-Object. I even defined my own alias.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot2.png\" alt=\"\" \/><span style=\"color: #44546a; font-size: 9pt;\"><em>Using Tee-MyObject<\/em><\/span><\/p>\n<p>To be clear, I have not modified, overwritten or removed Tee-Object. I have simply created a new version of the command with some additional functionality. If you have any questions on my process or some scripting element, please post a comment.<\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because I spend a great part of my day creating PowerShell related content, I often need to copy command output from a PowerShell session. The quick and dirty solution is to pipe my expression to the Clip.exe command line utility. get-service | where { $_.status -eq &#8216;running&#8217;} | clip This works in both the console&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New from the blog: Teeing Up to the Clipboard with #PowerShell","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[32,534,540,355],"class_list":["post-4489","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-functions","tag-powershell","tag-scripting","tag-tee-object"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Teeing Up to the Clipboard &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Teeing Up to the Clipboard &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Because I spend a great part of my day creating PowerShell related content, I often need to copy command output from a PowerShell session. The quick and dirty solution is to pipe my expression to the Clip.exe command line utility. get-service | where { $_.status -eq &#039;running&#039;} | clip This works in both the console...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2015-08-12T15:04:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-12T15:13:02+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Teeing Up to the Clipboard\",\"datePublished\":\"2015-08-12T15:04:55+00:00\",\"dateModified\":\"2015-08-12T15:13:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/\"},\"wordCount\":577,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/081215_1504_TeeingUptot1.png\",\"keywords\":[\"functions\",\"PowerShell\",\"Scripting\",\"Tee-Object\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/\",\"name\":\"Teeing Up to the Clipboard &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/081215_1504_TeeingUptot1.png\",\"datePublished\":\"2015-08-12T15:04:55+00:00\",\"dateModified\":\"2015-08-12T15:13:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/081215_1504_TeeingUptot1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/081215_1504_TeeingUptot1.png\",\"width\":733,\"height\":501},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4489\\\/teeing-up-to-the-clipboard\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Teeing Up to the Clipboard\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Teeing Up to the Clipboard &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/","og_locale":"en_US","og_type":"article","og_title":"Teeing Up to the Clipboard &#8226; The Lonely Administrator","og_description":"Because I spend a great part of my day creating PowerShell related content, I often need to copy command output from a PowerShell session. The quick and dirty solution is to pipe my expression to the Clip.exe command line utility. get-service | where { $_.status -eq 'running'} | clip This works in both the console...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/","og_site_name":"The Lonely Administrator","article_published_time":"2015-08-12T15:04:55+00:00","article_modified_time":"2015-08-12T15:13:02+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Teeing Up to the Clipboard","datePublished":"2015-08-12T15:04:55+00:00","dateModified":"2015-08-12T15:13:02+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/"},"wordCount":577,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png","keywords":["functions","PowerShell","Scripting","Tee-Object"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/","name":"Teeing Up to the Clipboard &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png","datePublished":"2015-08-12T15:04:55+00:00","dateModified":"2015-08-12T15:13:02+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/08\/081215_1504_TeeingUptot1.png","width":733,"height":501},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4489\/teeing-up-to-the-clipboard\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Teeing Up to the Clipboard"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2002,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/2002\/friday-fun-output-to-2-places-in-1\/","url_meta":{"origin":4489,"position":0},"title":"Friday Fun: Output to 2 Places in 1","author":"Jeffery Hicks","date":"January 13, 2012","format":false,"excerpt":"Today's Friday Fun comes out of a short exchange I had yesterday with Hal Rottenberg on Google Plus. We were playing around with piping a PowerShell command to Clip.exe which dumps the output to the Windows Clipboard. I got to thinking about taking this a step further based on my\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/01\/out-tee-1-300x141.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4581,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4581\/powershell-friday-fun-capture-the-command\/","url_meta":{"origin":4489,"position":1},"title":"PowerShell Friday Fun: Capture the Command","author":"Jeffery Hicks","date":"October 30, 2015","format":false,"excerpt":"This week's Friday Fun actually has a purpose, at least for me. But I always hope you'll pick up a tip or two that you can use in your own PowerShell work. Because I write a lot about PowerShell, I am constantly copying pasting between my PowerShell session and usually\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":693,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/693\/out-clip\/","url_meta":{"origin":4489,"position":2},"title":"Out-Clip","author":"Jeffery Hicks","date":"July 6, 2010","format":false,"excerpt":"I\u2019ve started working on the 2nd edition of Managing Active Directory with Windows PowerShell: TFM. As with almost all of my writing projects it will be full of PowerShell code examples. In the past I\u2019ve always relied on a manual copy and paste to add content to the manuscript. The\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2144,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2144\/have-your-output-and-variable-too\/","url_meta":{"origin":4489,"position":3},"title":"Have Your Output and Variable Too","author":"Jeffery Hicks","date":"March 29, 2012","format":false,"excerpt":"There's a relatively useful suggestion floating around on Twitter on how to save results of PowerShell command to a variable and see the results at the same time. PS C:\\> ($data=get-process) I'll admit this is a clever technique: you get the results from Get-Process written to the pipeline AND a\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4707,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4707\/a-better-powershell-more\/","url_meta":{"origin":4489,"position":4},"title":"A Better PowerShell More","author":"Jeffery Hicks","date":"December 23, 2015","format":false,"excerpt":"In PowerShell, when I have a lot of output, I can use the legacy more.com command to page the results to the screen. Get-Process | more There's not anything inherently wrong with this approach. Although one drawback is that it doesn't work in the PowerShell ISE. For that reason alone\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"More PowerShell Output","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=525%2C300 1.5x"},"classes":[]},{"id":37,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/37\/get-active-directory-user-information-in-powershell\/","url_meta":{"origin":4489,"position":5},"title":"Get Active Directory User Information in PowerShell","author":"Jeffery Hicks","date":"July 5, 2006","format":false,"excerpt":"One feature that PowerShell will likely be missing when it first ships is solid support for ADSI and working with Active Directory. You can use .NET DirectoryEntry objects but it feels more like programming and less like scripting. Another option for working with Active Directory in PowerShell is to use\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4489"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4489\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}