Here's the stub of what I'm trying to do:

function Set-test {
    Write-Verbose "Set-test: input obj= $inputObject" 

        foreach ($obj in $inputobject) {
            Write-Output $obj

function Get-test {
    $obj = New-Object PSObject
    $obj | Add-Member -MemberType NoteProperty -Name "swName" -Value "banana"
    $obj | Add-Member -MemberType NoteProperty -Name "Version" -Value "3.2.2"
    Write-Output "obj = $obj"
    $obj | Set-test -verbose    

Here's the output:

PS > Get-test
obj = @{swName=banana; Version=3.2.2}
VERBOSE: Set-test: input obj= 
Get-Process : Cannot evaluate parameter 'Name' because its argument is  specified as a script block and there is no input. A script block cannot be evaluated without input.
At C:\Users\username\Documents\WindowsPowerShell\Modules\mytool\mytools.psm1:204 char:13
+     PROCESS {
+             ~
+ CategoryInfo          : MetadataError: (:) [Get-Process], ParameterBindingException
+ FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Microsoft.PowerShell.Commands.GetProcessCommand

As seen from the verbose output it appears that the object is not being piped to the function and it has me baffled.

  • 1
    Just a quick tip. Please have a look at a technique called splatting that is a better solution than your way of creating objects in your function "Get-test". – megamorf May 22 '15 at 18:24

You can't have that write-verbose in the set-test outside of a begin{}, process{} or end{} block. It's messing things up. If you move it inside the process{} block it works fine.

  • 1
    Spot on! Be aware though, that $inputObject will behave differently inside the Process block, depending on whether the input was supplied through the pipeline or as a parameter – Mathias R. Jessen May 21 '15 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.