Home > Enterprise >  how to get file creation date in powershell
how to get file creation date in powershell

Time:07-24

I am trying to get file creation date into a variable in powershell, however unable to do so. The "$_.CreationTime" just prints the string literal ".CreationTime". How to get actual creation time of file?

    $builds = Get-ChildItem "$path_to_directory" *.zip | Where-Object {$_.CreationTime -gt $lastBuildDeployedTimestamp}
    foreach($build in $builds)
    {
                            "$path_to_directory"
                            "$_.CreationTime"
    }

CodePudding user response:

Use "$($_.CreationTime)" .

In your particular example it should be "$($build.CreationTime)"

CodePudding user response:

A one liner approach would be Get-ChildItem $path_to_directory *.zip | Where-Object {$_.CreationTime -gt $lastBuildDeployedTimestamp} | Select-Object -Property FullName, CreationTime

However, if you'd like to keep your loop then you'll need to use $build.

$builds = Get-ChildItem $path_to_directory *.zip | Where-Object {$_.CreationTime -gt $lastBuildDeployedTimestamp} 
foreach($build in $builds)
{
    $path_to_directory
    $build.CreationTime
}

For more info see Get-Help about_Foreach -Full

  • Related