Reputation: 189
I have a script that writes output to a log file and also the console. I am running the command Add-WindowsFeatures... I want to take output of this command and pipe it to my script. Is it possible?
Upvotes: 0
Views: 3525
Reputation: 18146
Absolutely. You just need to include the CmdletBinding attribute on your param statement. Then, add an attribute to one of your parameters which details the way the pipeline input binds to the parameter. For instance put this in c:\temp\get-extension.ps1:
[CmdletBinding()]
Param(
[parameter(Mandatory=$true,
ValueFromPipeline=$true)][System.IO.FileInfo[]]$file
)
process {
$file.Extension
}
Then, you can do this:
dir -File| C:\temp\get-extension.ps1
updating to address the latest comment: I'm guessing that setting the parameter type to [object[]]$stuff
rather than [fileinfo[]]
and putting
$stuff | out-file c:\logs\logfile.txt #or wherever you want
in the process block will get you close.
Upvotes: 4