Passing fileinfo to function

This topic contains 2 replies, has 3 voices, and was last updated by  Daniel Krebs 3 years, 5 months ago.

  • Author
  • #22295

    Itamar Tziger

    this is my function
    function Write-Log
    # Param1 help description


    $logfile = "c:\$(get-date -format 'ddmmmmyyyy_hhmmtt').txt"

    $FullName | Out-File -Append -FilePath $logfile
    I want to pass fileinfo object to this function but I get error:
    Write-Log : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties
    do not match any of the parameters that take pipeline input."

    Please advice

  • #22296

    Tim Pringle

    Hi Itamar,

    I think it's because you don't appear to be defining $FullName.

    If you're trying to reference the FullName property of the $FileInfo object, you need to refer to it like this

    $FileInfo.FullName | Out-File -Append -FilePath $logfile
  • #22300

    Daniel Krebs

    You will need to add ValueFromPipeline=$true to your parameters if you want something like below to work:

    Get-Item -Path C:\Windows\Explorer.exe | Write-Log

You must be logged in to reply to this topic.