Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Passing objects into functions

$
0
0

I'm trying to do what I thuink should be a simple thing but it's just not working. I wrote a sample function and I'm passing an object and then referencing the properties of it. But the output only shows the object name twice, not the properties I want.

Shouldn't this work?

function test-passing {

    [CmdletBinding(SupportsShouldProcess=$true)]

    param(
        [parameter(
            Position=0, 
            Mandatory=$true,
            ValueFromPipeline=$True,
            ValueFromPipelineByPropertyName=$true)]
        $Length,
        
        [parameter(
            Position=1, 
            Mandatory=$true,
            ValueFromPipeline=$True,
            ValueFromPipelineByPropertyName=$true)]
        $LastWriteTime
    
    )
    process{
        Write-Host $LastWriteTime
        Write-Host $Length
    }
}

Get-ChildItem | test-passing


Viewing all articles
Browse latest Browse all 2562


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>