Passing fileinfo to function

this is my function
function Write-Log
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(ValueFromPipelineByPropertyName=$true)]
[System.IO.FileInfo[]]$FileInfo,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[System.IO.DirectoryInfo[]]
$DirectoryInfo

)

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

}
Process
{
    $FullName | Out-File -Append -FilePath $logfile 
}
End
{
}

}
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

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

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