On the ebook Learn PowerShell Toolmaking in a Month of Lunches
there is a lab in the chapiter 26, with a challenges, Get-Service | Export-TDF c:\services.tdf,
when i try changing the code in the proxy function with $scriptCmd = { & $wrappedCmd @PSBoundParameters -delimiter "t"}` ,
the result is an error when calling the export-tdf proxy function :
`Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid.It must result in a
command name, a script block, or a CommandInfo object"
Before we proceed … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Since not all of us have access to that book or have read it already … could you please share at least all the relevant code here completely along with the complete error message (both formatted as code, please)?
#proxy function
<#
First, we need to run these lines to create the metadata:
$metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command Export-CSV)
Chapter 26 lab 83
[System.Management.Automation.ProxyCommand]::Create($metadata) | Out-File ProxyExportCSV.ps1
#>
Function Export-TDF {
#we deleted the help link in cmdletbinding and added our own
<#
.Synopsis
Export to tab delimited file
.Description
This is a proxy command to Export-CSV which is hard coded to export
data to a tab-delimited file.
#>
[CmdletBinding(DefaultParameterSetName='Delimiter',SupportsShouldProcess=$true,ConfirmImpact='Medium')]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[psobject]
${InputObject},
[Parameter(Position=0)]
[ValidateNotNullOrEmpty()]
[string]
${Path},
[Alias('PSPath')]
[ValidateNotNullOrEmpty()]
[string]
${LiteralPath},
[switch]
${Force},
[Alias('NoOverwrite')]
[switch]
${NoClobber},
[ValidateSet('Unicode','UTF7','UTF8','ASCII','UTF32','BigEndianUnicode','Default','OEM')]
[string]
${Encoding},
[switch]
${Append},
#we deleted the Delimiter parameter that used to be here
[Parameter(ParameterSetName='UseCulture')]
[switch]
${UseCulture},
[Alias('NTI')]
[switch]
${NoTypeInformation})
begin
{
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('ExportCsv', [System.Management.Automation.CommandTypes]::Cmdlet)
<#
we added a hard coded reference to include the original -delimiter parameter
with the tab character.
#>
$scriptCmd = { & $wrappedCmd @PSBoundParameters -delimiter "`t"}
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}
process
{
try {
$steppablePipeline.Process($_)
} catch {
throw
}
}
end
{
try {
$steppablePipeline.End()
} catch {
throw
}
}
#We deleted the links for forwarded help
} #end function
#test it out
Get-Service -Name winrm | Export-TDF c:\services.tdf