Write file created dateRSS

0 replies

Last post Feb 06, 2020 06:27 AM by learncs

  • Write file created date

    Feb 06, 2020 06:27 AM|learncs|LINK

    Hi, I am using Windows powershell 5 and trying to write the file created date using Write-Host in the code below. When I execute the script I get "File date: $file.CreationTime.Date" but not the file created date. Could you please guide me.

    $file = "<path of file>"
    if($file = Get-Item $file -ErrorAction 0){
    	if($file.CreationTime.Date -ne [datetime]::Today) {
    		Send-MailMessage -SmtpServer <String> -Subject <String> -From <String> -To <String>
    		Write-Host 'File date: $file.CreationTime.Date'
    	}else{
    		Write-Host 'File date: $file.CreationTime.Date'
        }
    }

    Thank you.