Hi @Tulik23 K ,
maybe this helps:
$today = (Get-Date).ToString('yyyyMMdd')
$allFiles = Get-ChildItem -Path .\Junk
foreach ($file in $allFiles) {
if ($file.CreationTime.ToString('yyyyMMdd') -eq $today) {
Write-Output "File $($file.Name) has beens created on $($file.CreationTime)"
}
else {
Write-Output "$($file.Name) has been created before today"
}
}
Or just a little shorter:
$today = (Get-Date).ToString('yyyyMMdd')
Get-ChildItem -Path .\Junk | ForEach-Object {
if ($_.CreationTime.ToString('yyyyMMdd') -eq $today) {
Write-Output "File $($_.Name) has beens created on $($_.CreationTime)"
}
else {
Write-Output "$($_.Name) has been created before today"
}
}
If this doesn't work for you please post your script here to see the details and running the script for testing. Please use the Code Sample - Ctrl-K
option in the editor (the icon with 101010
) to post scripts here. The Q&A editor is screwing up script code in the normal editor window.
Also if you get an error message the content of the message would be helpful.
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten