ricardo felix
ricardo felix

Reputation: 11

Powershell script to check for a file that was created on the date of today

I am writing a script for my company. One of the goals of this script is to check in a directory if a File was created today. It should then return the message that the File exists or the file does not exist in case there is no file that was created today. Below you can see how far I have gotten. I have also already experimented with the Test-Path command but had no success.

$FOUND = $True

$dir = "directory path" #Cant put the real directory path in here out of security reasons

$latest = Get-ChildItem -Path $dir | Where-Object {$_.CreationTime -gt (Get-Date).Date}

if($Path -eq $FOUND) {
    Write-Host 'File exists'
}
else {
    Write-Host 'File does not exist'
}

I have also tried with an if-else statement.

Hope you can help Thanks

Upvotes: 1

Views: 4264

Answers (1)

חִידָה
חִידָה

Reputation: 279

How to Get File updated Today in Powershell?

 Get-ChildItem -Path C:\Users\Username\Desktop\Folder | where {([datetime]::now.Date -eq $_.lastwritetime.Date)};

Upvotes: 1

Related Questions