Brad, you could probably use FileSystemWatcher See https://dereknewton.com/2011/05/monitoring-file-system-changes-with-powershell/ for more help with this as I have not used it much. Below is the code from this site. In the action sections you can write whatever code you want when an event is triggered i.e. send an email etc
Each night i get a folder created in the location. For example last night the folder was called 1972017
The night before was called 1872017
This script will run early in the morning. My script so far selects
$logs = Get-ChildItem -Path $latest -Recurse -file | where { $_.CreationTime.Date -gt (Get-Date).AddDays(-1)}
Which shows me the files created but what i want to do is select the folder
$latest = Get-ChildItem -Path $Path | Sort-Object LastAccessTime -Descending | Select-Object -First 1 and then drill down to get the two files selected.
If you had something like this running eveytime a new folder is it would overwrite the contents of newfolder.txt you could always append if more than one folder is going to be created
so in your original script you could run
$path = get-content c:\test\newfolder.txt
The below script has to be running when the folder is created
Thanks,
The Files contained within 1972017 will be two files
VerifiedDataTransfers.txt and SuccessfulDataTransfers.txt
so once i have selected the folder, i want to confirm these two files are here.
Then if they are both here then i will be doing something with these using sql.
Currently its showing as write-host “Found both” or “not found” but these will be doing more.
so i need to confirm the most recent folder which will be created at 23:30 every night has the two files.
I don’t want think i need to write this to a text file do i?
i need to get the contents of a folder?
Missing a . in $pathfullname line should read
$logs = Get-ChildItem -Path $path.fullname -Recurse -file | where { $_.CreationTime.Date -gt (Get-Date).AddDays(-3)}