Skip to content

Instantly share code, notes, and snippets.

@apharp
Created June 8, 2023 14:50
Show Gist options
  • Save apharp/534fdaa626bf87032fe4fb77f95192a7 to your computer and use it in GitHub Desktop.
Save apharp/534fdaa626bf87032fe4fb77f95192a7 to your computer and use it in GitHub Desktop.
# Define the file path
$filePath = "C:\Path\To\Your\File.ext"
# Get the current date
$today = Get-Date -Format "yyyy-MM-dd"
# Get the creation date of the file
$file = Get-Item $filePath
$creationDate = $file.CreationTime.Date
# Compare the creation date with today's date
if ($creationDate -eq $today) {
Write-Output "The file was created today."
} else {
Write-Output "The file was not created today."
# Define event details
$eventLog = "Application"
$source = "YourScript"
$eventID = 1001
$message = "The file '$filePath' was not created today."
# Write event to the Event Viewer
Write-EventLog -LogName $eventLog -Source $source -EventID $eventID -EntryType Warning -Message $message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment