If I run the following command.
#Parameters
$Path = "C:UserstestAppDataLocalTemp" # Path where the file is located
$Days = "1" # Number of days before current date
#Calculate Cutoff date
$CutoffDate = (Get-Date).AddDays(-$Days)
#Get All Files modified more than the last 30 days
Get-ChildItem -Path $Path -Recurse -File | Where-Object { $_.CreationTime -lt $CutoffDate } | Remove-Item –Force -Verbose
and i get the following errors for the folders
Get-ChildItem : Access to the path 'C:UsersToolAppDataLocalTempmsdtadmin' is denied.
At line:1 char:1
+ Get-ChildItem -Path $Path -Recurse -File | Where-Object { $_.Creation ...
Now when I run in admin mode I get nothing. and all the folders are still there. basically I make a share folder and want all files older than 14 days of creation are deleted and run a task every day at midnight on a windows 2019 server. Can anyone explain whats going on here? Im using current directory to test.