Created
June 8, 2023 14:50
-
-
Save apharp/534fdaa626bf87032fe4fb77f95192a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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