{"id":7879,"date":"2014-10-06T06:00:00","date_gmt":"2014-10-06T13:00:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=7879"},"modified":"2014-10-04T13:08:18","modified_gmt":"2014-10-04T20:08:18","slug":"the-passthru-parameter-gimme-output","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2014\/10\/06\/the-passthru-parameter-gimme-output\/","title":{"rendered":"The PassThru Parameter: Gimme Output"},"content":{"rendered":"<p>I love to explain things in clear, simple terms. So, a few weeks ago, I tweeted a request for a Windows PowerShell concept that could use more explanation. Andy Fair (@ravensportal) from Oklahoma City asked for a clear explanation of the <strong>PassThru<\/strong> parameter. PassThru is frequently used and frequently ignored, so I\u2019m taking him up on his idea. Thanks, Andy!<\/p>\n<p>The PassThru parameter lets you request output from cmdlets that return no output by default. It\u2019s used most often to verify that the cmdlet did what you intended.<\/p>\n<p>&nbsp;<\/p>\n<h3>Using the PassThru Parameter<\/h3>\n<p>In Windows PowerShell, Get-* cmdlets almost always return the object that they get. New-* cmdlets typically return the objects that they create. Add-*, Format-*, Convert-*, and Update-* cmdlets sometimes return the objects that they\u2019ve changed. But many cmdlets return nothing \u2013 at least by default.<\/p>\n<p>For example, the Copy-Item cmdlet doesn\u2019t return anything. It just copies the object in the path to the specified destination. In this case, it copied the OutputFile.txt file to the CopyTest subdirectory.<\/p>\n<blockquote>\n<pre>    <span style=\"font-weight: bold; color: #c00000;\">PS<\/span><span style=\"color: #000000;\"> C:\\&gt; <\/span><em><span style=\"color: #00008b;\">Copy-Item<\/span><\/em> <span style=\"color: #0000ff;\">-<\/span><span style=\"color: #000000;\">Path C:\\ps-test\\OutputFile.txt <\/span><span style=\"color: #0000ff;\">-<\/span><span style=\"color: #000000;\">Destination .\\CopyTest\r\n    <\/span><span style=\"font-weight: bold; color: #c00000;\">PS<\/span><span style=\"color: #000000;\"> C:\\&gt; <\/span><\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>This is fine, because I typically don\u2019t want any noise in my scripts. But, if I want to verify that the file got to its intended destination, I need to run a Get-ChildItem or Test-Path command. Or, I can use the <strong>PassThru<\/strong> parameter of Copy-Item. In Copy-Item, the PassThru parameter returns the copied item in its new location.<\/p>\n<blockquote>\n<pre>    <span style=\"font-weight: bold; color: #c00000;\">PS<\/span><span style=\"color: #000000;\"> C:\\&gt; <\/span>Copy-Item <span style=\"color: #0000ff;\">-<\/span><span style=\"color: #000000;\">Path .\\OutputFile.txt <\/span><span style=\"color: #0000ff;\">-<\/span><span style=\"color: #000000;\">Destination .\\CopyTest\\OutputFile.txt \u2013PassThru\r\n\r\n    <\/span><span style=\"color: #696969;\">Directory<\/span><span style=\"color: #0000ff;\">:<\/span><span style=\"color: #000000;\"> C:\\ps-test\\CopyTest\r\n\r\n    <\/span><span style=\"font-weight: bold; color: #0000ff;\">Mode<\/span><span style=\"color: #000000;\">                LastWriteTime     Length Name\r\n    <\/span><span style=\"color: #0000ff;\">----<\/span> <span style=\"color: #0000ff;\">-------------<\/span> <span style=\"color: #0000ff;\">------<\/span> <span style=\"color: #0000ff;\">----<\/span>\r\n    <span style=\"color: #696969;\">-a<\/span><span style=\"color: #0000ff;\">---<\/span>         <span style=\"color: #000000;\">2<\/span><span style=\"color: #0000ff;\">\/<\/span><span style=\"color: #000000;\">24<\/span><span style=\"color: #0000ff;\">\/<\/span><span style=\"color: #000000;\">2014<\/span>   <span style=\"color: #000000;\">8<\/span><span style=\"color: #0000ff;\">:<\/span><span style=\"color: #000000;\">43<\/span><span style=\"color: #000000;\"> PM         <\/span><span style=\"color: #000000;\">20<\/span><span style=\"color: #000000;\"> OutputFile.txt    <\/span><\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>In a script, I can save the output to a variable and check it before I execute the next command.<\/p>\n<blockquote>\n<pre>    <span style=\"color: #8b0000;\">$file<\/span> <span style=\"color: #0000ff;\">=<\/span> <span style=\"font-weight: bold; color: #0000ff;\">Copy-Item<\/span> <span style=\"color: #3399ff;\">-Path<\/span><span style=\"color: #000000;\"> .\\OutputFile.txt <\/span><span style=\"color: #3399ff;\">-Destination<\/span><span style=\"color: #000000;\"> .\\CopyTest\\OutputFile.txt \u2013PassThru\r\n    <\/span><span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #8b0000;\">$file<\/span><span style=\"color: #000000;\">) { \u2026&lt;<\/span><span style=\"color: #696969;\">keep<\/span><span style=\"color: #000000;\"> going&gt;\u2026 }   <\/span><\/pre>\n<pre>-or-<\/pre>\n<pre>    <span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #8b0000;\">$file<\/span><span style=\"color: #000000;\">.FullName \u2013<\/span><span style=\"color: #696969;\">like<\/span><span style=\"color: #000000;\"> \u201c*CopyTest\\OutputFile.txt\u201d) { \u2026&lt;<\/span><span style=\"color: #696969;\">keep<\/span><span style=\"color: #000000;\"> going&gt;\u2026. }<\/span><\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>When using the PassThru parameter of a command, be sure to check the type of the object that it returns. This information should be in the help file for the command, either in the description of the PassThru parameter or the Outputs section of the cmdlet help file.<\/p>\n<p>For example, the help for Copy-Item says:<\/p>\n<blockquote><p>\u201cWhen you use the PassThru parameter, Copy-Item returns an object that represents the copied item. Otherwise, this cmdlet does not generate any output.\u201d<\/p><\/blockquote>\n<p>It\u2019s important to check before writing your verification code (e.g. if ($file) ), because not all cmdlets return the object that they change. For example, when the cmdlets in the Azure module (Azure Service Management) have a PassThru parameter, they return a Boolean value &#8212; $True or $False\u00a0 &#8212; that represents the success ($True) or failure ($False) of the command.<\/p>\n<p>For example, the Get-AzurePublishSettingsFile cmdlet\u00a0downloads an identity file, but it does not return an object that represents the file or its secure location. By default, the cmdlet returns nothing, but if you use its PassThru parameter, it returns $True or $False.<\/p>\n<blockquote>\n<pre>    <span style=\"color: #8b0000;\">$result<\/span> <span style=\"color: #0000ff;\">=<\/span> <span style=\"color: #696969;\">Get-AzurePublishSettingsFile<\/span>\r\n    <span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #8b0000;\">$result<\/span><span style=\"color: #000000;\">) { \u2026&lt;<\/span><span style=\"color: #696969;\">keep<\/span><span style=\"color: #000000;\"> going&gt;\u2026 }<\/span><\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h3>Find the PassThru Parameter<\/h3>\n<p>To find cmdlets in your modules that have the PassThru parameter, use a command like this one. It runs a Get-Command command and saves the results in the $c variable. Then it uses the Where-Object cmdlet to find parameters with the name \u201cPassThru.\u201d If it finds a PassThru parameter, it returns the cmdlet that was saved in the $c pipeline variable. (I\u2019m running Windows PowerShell 4.0, but this command should work on 3.0 and later.)<\/p>\n<blockquote>\n<pre><span style=\"font-weight: bold; color: #0000ff;\">Get-Command<\/span> <span style=\"color: #000000;\">-PipelineVariable c <\/span><span style=\"color: #0000ff;\">|<\/span> \r\n    <span style=\"font-weight: bold; color: #c00000;\">where<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #8b0000;\">$_<\/span><span style=\"color: #000000;\">.ParameterSets.Parameters.Name <\/span><span style=\"color: #0000ff;\">-eq<\/span> <span style=\"color: #ff0000;\">\"PassThru\"<\/span><span style=\"color: #000000;\"> } <\/span><span style=\"color: #0000ff;\">|<\/span> \r\n<span style=\"font-weight: bold; color: #0000ff;\">        <strong>ForEach-Object<\/strong><\/span><span style=\"color: #000000;\"> {<\/span><span style=\"color: #8b0000;\">$c<\/span><span style=\"color: #000000;\">}<\/span><\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>On my machine, it returned 48 cmdlets with the following distribution of verbs. It\u2019s really all over the place.<\/p>\n<blockquote><p><span style=\"font-family: Lucida Console; font-size: small;\">PS C:\\&gt;\u00a0 $pass | Group-Object -Property Verb<br \/>\nCount Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Group<br \/>\n&#8212;&#8211; &#8212;-\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8212;&#8211;<br \/>\n6 Add\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Add-Computer, Add-Content, Add-History, Add-Member&#8230;}<br \/>\n2 Clear\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Clear-ItemProperty, Clear-Variable}<br \/>\n1 Compare\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Compare-Object}<br \/>\n2 Copy\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Copy-Item, Copy-ItemProperty}<br \/>\n1 Disable\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Disable-PSBreakpoint}<br \/>\n1 Enable\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Enable-PSBreakpoint}<br \/>\n1 Export\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Export-Alias}<br \/>\n2 Import\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Import-Alias, Import-Module}<br \/>\n2 Invoke\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Invoke-RestMethod, Invoke-WebRequest}<br \/>\n2 Move\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Move-Item, Move-ItemProperty}<br \/>\n3 New\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{New-Alias, New-ModuleManifest, New-Variable}<br \/>\n1 Out\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Out-GridView}<br \/>\n1 Pop\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Pop-Location}<br \/>\n1 Push\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Push-Location}<br \/>\n2 Remove\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Remove-Computer, Remove-PSSnapin}<br \/>\n3 Rename\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Rename-Computer, Rename-Item, Rename-ItemProperty}<br \/>\n1 Restart\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Restart-Service}<br \/>\n1 Resume\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Resume-Service}<br \/>\n8 Set\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Set-Alias, Set-Content, Set-Item, Set-ItemProperty&#8230;}<br \/>\n1 Show\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Show-Command}<br \/>\n2 Start\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{Start-Process, Start-Service}\u00a0 <\/span><\/p><\/blockquote>\n<pre><\/pre>\n<p>&nbsp;<\/p>\n<h3>Implement the PassThru Parameter<\/h3>\n<p>You can also add the PassThru parameter to the scripts and functions that you write. Because PassThru doesn\u2019t take a value, its parameter type is always <strong>Switch<\/strong> or <strong>SwitchParameter<\/strong>, regardless of the type of the object that it returns. And, PassThru parameters should always be optional (not mandatory). For example, I have a little script that adds a timestamp to the file name. By default, it doesn\u2019t return any output, so I always run a Get-Item or Test-Path when it completes. Instead, I\u2019ll add a PassThru parameter. Here\u2019s the \u201cbefore\u201d version:<\/p>\n<pre>    <span style=\"color: #0000ff;\">Param<\/span><span style=\"color: #000000;\">\r\n            (\r\n                [<\/span><span style=\"color: #4682b4;\">parameter<\/span><span style=\"color: #000000;\">(Mandatory<\/span><span style=\"color: #0000ff;\">=<\/span><span style=\"color: #8b0000;\">$True<\/span><span style=\"color: #000000;\">)]\r\n                [<\/span><span style=\"color: #0000cd;\">String<\/span><span style=\"color: #000000;\">]\r\n                <\/span><span style=\"color: #8b0000;\">$FilePath<\/span><span style=\"color: #000000;\">\r\n            )\r\n\r\n    <\/span><span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #0000ff;\">!<\/span><span style=\"color: #000000;\">(<\/span><span style=\"font-weight: bold; color: #0000ff;\">Test-Path<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span><span style=\"color: #000000;\">)) {<\/span><span style=\"color: #0000ff;\">throw<\/span> <span style=\"color: #ff0000;\">\"Can't find file\\folder at $filepath\"<\/span><span style=\"color: #000000;\">}\r\n\r\n    <\/span><span style=\"color: #8b0000;\">$item<\/span> <span style=\"color: #0000ff;\">=<\/span> <span style=\"font-weight: bold; color: #0000ff;\">Get-Item<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span>\r\n    <span style=\"color: #8b0000;\">$timestamp<\/span> <span style=\"color: #0000ff;\">=<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"font-weight: bold; color: #0000ff;\">Get-Date<\/span> <span style=\"color: #8b0000;\">$item<\/span><span style=\"color: #000000;\">.Lastwritetime <\/span><span style=\"color: #3399ff;\">-Format<\/span><span style=\"color: #000000;\"> o) <\/span><span style=\"color: #0000ff;\">-replace<\/span> <span style=\"color: #ff0000;\">\":\"<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #ff0000;\">\"-\"<\/span> \r\n\r\n    <span style=\"color: #8b0000;\">$newname<\/span> <span style=\"color: #0000ff;\">=<\/span> <span style=\"color: #8b0000;\">$item<\/span><span style=\"color: #000000;\">.BaseName <\/span><span style=\"color: #0000ff;\">+<\/span> <span style=\"color: #ff0000;\">\"-\"<\/span> <span style=\"color: #0000ff;\">+<\/span> <span style=\"color: #8b0000;\">$timestamp<\/span> <span style=\"color: #0000ff;\">+<\/span> <span style=\"color: #8b0000;\">$item<\/span><span style=\"color: #000000;\">.Extension<\/span>\r\n    <span style=\"font-weight: bold; color: #0000ff;\">Rename-Item<\/span> <span style=\"color: #3399ff;\">-Path<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span> <span style=\"color: #3399ff;\">-NewName<\/span> <span style=\"color: #8b0000;\">$newname<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>Now, I\u2019ll add a PassThru parameter. It\u2019s optional and the parameter type is Switch. I also add a line of code at the end that checks the value of that PassThru parameter. Switch parameters have a Boolean ($True\/$False) value. The value is $True if the parameter is used (IsPresent) in the command and $False if it is not used.<\/p>\n<p>In my code, if the PassThru parameter is $True ( if ($PassThru) ), I call the Get-Item cmdlet to return the file with the new name.<\/p>\n<pre>    <span style=\"color: #0000ff;\">Param<\/span><span style=\"color: #000000;\">\r\n    (\r\n        [<\/span><span style=\"color: #4682b4;\">parameter<\/span><span style=\"color: #000000;\">(Mandatory <\/span><span style=\"color: #0000ff;\">=<\/span> <span style=\"color: #8b0000;\">$True<\/span><span style=\"color: #000000;\">)]\r\n        [<\/span><span style=\"color: #0000cd;\">String<\/span><span style=\"color: #000000;\">]\r\n        <\/span><span style=\"color: #8b0000;\">$FilePath<\/span><span style=\"color: #000000;\">,\r\n        \r\n        [<\/span><span style=\"color: #4682b4;\">parameter<\/span><span style=\"color: #000000;\">(Mandatory <\/span><span style=\"color: #0000ff;\">=<\/span> <span style=\"color: #8b0000;\">$False<\/span><span style=\"color: #000000;\">)]\r\n        [<\/span><span style=\"color: #0000cd;\">Switch<\/span><span style=\"color: #000000;\">]\r\n        <\/span><span style=\"color: #8b0000;\">$PassThru<\/span><span style=\"color: #000000;\">\r\n    )\r\n\r\n    <\/span><span style=\"color: #808080;\"><span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #0000ff;\">!<\/span><span style=\"color: #000000;\">(<\/span><span style=\"font-weight: bold; color: #0000ff;\">Test-Path<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span><span style=\"color: #000000;\">)) { <\/span><span style=\"color: #0000ff;\">throw<\/span> <span style=\"color: #ff0000;\">\"Can't find file\\folder at $filepath\"<\/span><\/span><span style=\"color: #808080;\"><span style=\"color: #000000;\"> }\r\n\r\n    <\/span><span style=\"color: #8b0000;\">$item<\/span> <span style=\"color: #0000ff;\">=<\/span> <span style=\"font-weight: bold; color: #0000ff;\">Get-Item<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span><\/span>\r\n    <span style=\"color: #808080;\"><span style=\"color: #8b0000;\">$timestamp<\/span> <span style=\"color: #0000ff;\">=<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"font-weight: bold; color: #0000ff;\">Get-Date<\/span> <span style=\"color: #8b0000;\">$item<\/span><span style=\"color: #000000;\">.Lastwritetime <\/span><span style=\"color: #3399ff;\">-Format<\/span><span style=\"color: #000000;\"> o) <\/span><span style=\"color: #0000ff;\">-replace<\/span> <span style=\"color: #ff0000;\">\":\"<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #ff0000;\">\"-\"<\/span><\/span>\r\n\r\n    <span style=\"color: #808080;\"><span style=\"color: #8b0000;\">$newname<\/span> <span style=\"color: #0000ff;\">=<\/span> <span style=\"color: #8b0000;\">$item<\/span><span style=\"color: #000000;\">.BaseName <\/span><span style=\"color: #0000ff;\">+<\/span> <span style=\"color: #ff0000;\">\"-\"<\/span> <span style=\"color: #0000ff;\">+<\/span> <span style=\"color: #8b0000;\">$timestamp<\/span> <span style=\"color: #0000ff;\">+<\/span> <span style=\"color: #8b0000;\">$item<\/span><\/span><span style=\"color: #808080;\"><span style=\"color: #000000;\">.Extension\r\n<\/span><\/span>    <span style=\"color: #808080;\"><span style=\"font-weight: bold; color: #0000ff;\">Rename-Item<\/span> <span style=\"color: #3399ff;\">-Path<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span> <span style=\"color: #3399ff;\">-NewName<\/span> <span style=\"color: #8b0000;\">$newname<\/span><\/span>\r\n\r\n    <span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #8b0000;\">$PassThru<\/span><span style=\"color: #000000;\">) { <\/span><span style=\"font-weight: bold; color: #0000ff;\">Get-Item<\/span> <span style=\"color: #8b0000;\">$newname<\/span><span style=\"color: #000000;\"> }<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>But, wait! The Rename-Item cmdlet that I call to change the file name has a PassThru parameter that returns the item that it renamed. All I need to do is to pass the value of my PassThru parameter to the PassThru parameter of Rename-Item.<\/p>\n<p>Switch parameters can take a $True or $False value. Just type a colon (:) after the parameter name and then type the Boolean value. Here\u2019s the syntax:<\/p>\n<pre>    <span style=\"color: #3399ff;\">-PassThru<\/span><span style=\"color: #0000ff;\">:<\/span><span style=\"color: #8b0000;\">$True<\/span>\r\n    <span style=\"color: #3399ff;\">-PassThru<\/span><span style=\"color: #0000ff;\">:<\/span><span style=\"color: #8b0000;\">$False<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>Because my PassThru parameter also has a Boolean value, I can type the colon and then type the $PassThru parameter.<\/p>\n<p>So I can replace:<\/p>\n<pre>    <span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #8b0000;\">$PassThru<\/span><span style=\"color: #000000;\">) { <\/span><span style=\"font-weight: bold; color: #0000ff;\">Get-Item<\/span> <span style=\"color: #8b0000;\">$newname<\/span><span style=\"color: #000000;\"> }\r\n<\/span><\/pre>\n<p>&#8230; with a Rename-Item command that uses the PassThru parameter:<\/p>\n<pre>    <span style=\"font-weight: bold; color: #0000ff;\">Rename-Item<\/span> <span style=\"color: #3399ff;\">-Path<\/span> <span style=\"color: #8b0000;\">$FilePath<\/span> <span style=\"color: #3399ff;\">-NewName<\/span> <span style=\"color: #8b0000;\">$newname<\/span> <span style=\"color: #3399ff;\">-PassThru<\/span><span style=\"color: #0000ff;\">:<\/span><span style=\"color: #8b0000;\">$PassThru\r\n<\/span>\r\n<\/pre>\n<p>This instance of reusing the PassThru parameter of Rename-Item isn\u2019t just a corner case. In almost all of my scripts and functions that have a PassThru parameter, I just reuse the PassThru parameter of the final command.<\/p>\n<p>&nbsp;<\/p>\n<p>Thanks again for the question, Andy. If you\u2019d like me to explain a Windows PowerShell concept, or something that you\u2019ve seen in a forum or blog post, just let me know.<\/p>\n<p><i>June Blender is a technology evangelist at SAPIEN Technologies, Inc. You can reach her at <a href=\"mailto:juneb@sapien.com\">juneb@sapien.com<\/a> or follow her on Twitter at <a href=\"https:\/\/twitter.com\/juneb_get_help\">@juneb_get_help<\/a>.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love to explain things in clear, simple terms. So, a few weeks ago, I tweeted a request for a Windows PowerShell concept that could use more explanation. Andy Fair (@ravensportal) from Oklahoma City asked for a clear explanation of the PassThru parameter. PassThru is frequently used and frequently ignored, so I\u2019m taking him up [&hellip;]<\/p>\n","protected":false},"author":31,"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,"footnotes":""},"categories":[25],"tags":[934,28],"class_list":["post-7879","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-juneb","tag-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/7879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=7879"}],"version-history":[{"count":11,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/7879\/revisions"}],"predecessor-version":[{"id":7904,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/7879\/revisions\/7904"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=7879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=7879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=7879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}