Hi Folks,<\/p>\n
I want to create a Powershell script and schedule it as a task on my windows server for every 1 hour.
\nSo that it will monitor for a particular file type (if that arrives in last 1 hour) in a folder and it’s subfolders on a NAS drive and send me an email alert with file list and its folder/subfolder names.<\/p>\n
Can anyone please help me in getting any sample script for the same.<\/p>\n
Thanks!!<\/p>\n
#Path folder\n$checkForFiles = \"C:\\Users\\nkuma299\\Desktop\\Folder_File_Test\\Test\\*\"\n#Test for the existence of files\n$computer = read-host \"ge3rnas01cifs1\"\nif(Test-Path \\\\$computer\\200002679_VOL01\\HUB\\INVEXP_E3\\Processing){\n$computer \"/yes`n\" | out-file C:\\Users\\nkuma299\\Desktop\\Folder_File_Test\\log.txt -append}\nelse{$computer \"/no`n\" |out-file C:\\Users\\nkuma299\\Desktop\\Folder_File_Test\\log.txt -append}\n\n$fileExistence = test-path $checkForFiles.Filter = \"*.*\"\n$fileExistence\n#check for the existence of files in the folder\n if ($fileExistence -eq $true) \n\t{\n send-mailmessage -subject \"File Unprocessed\" -from [email protected] -to [email protected] `\n -smtpserver SMTP-TEST.xyz.com \n\t}\n # If no files exist, do nothing\n else\n {write-host \"nothing to process\"}\n\n<\/code><\/pre>","upvoteCount":2,"answerCount":4,"datePublished":"2020-08-05T01:53:16.000Z","author":{"@type":"Person","name":"neeraj21","url":"https://community.spiceworks.com/u/neeraj21"},"suggestedAnswer":[{"@type":"Answer","text":"Hi Folks,<\/p>\n
I want to create a Powershell script and schedule it as a task on my windows server for every 1 hour.
\nSo that it will monitor for a particular file type (if that arrives in last 1 hour) in a folder and it’s subfolders on a NAS drive and send me an email alert with file list and its folder/subfolder names.<\/p>\n
Can anyone please help me in getting any sample script for the same.<\/p>\n
Thanks!!<\/p>\n
#Path folder\n$checkForFiles = \"C:\\Users\\nkuma299\\Desktop\\Folder_File_Test\\Test\\*\"\n#Test for the existence of files\n$computer = read-host \"ge3rnas01cifs1\"\nif(Test-Path \\\\$computer\\200002679_VOL01\\HUB\\INVEXP_E3\\Processing){\n$computer \"/yes`n\" | out-file C:\\Users\\nkuma299\\Desktop\\Folder_File_Test\\log.txt -append}\nelse{$computer \"/no`n\" |out-file C:\\Users\\nkuma299\\Desktop\\Folder_File_Test\\log.txt -append}\n\n$fileExistence = test-path $checkForFiles.Filter = \"*.*\"\n$fileExistence\n#check for the existence of files in the folder\n if ($fileExistence -eq $true) \n\t{\n send-mailmessage -subject \"File Unprocessed\" -from [email protected] -to [email protected] `\n -smtpserver SMTP-TEST.xyz.com \n\t}\n # If no files exist, do nothing\n else\n {write-host \"nothing to process\"}\n\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2020-08-05T01:53:16.000Z","url":"https://community.spiceworks.com/t/powershell-script-to-monitor-folders-on-nas-drive/771450/1","author":{"@type":"Person","name":"neeraj21","url":"https://community.spiceworks.com/u/neeraj21"}},{"@type":"Answer","text":"What have you tried where are you stuck?<\/p>\n
look into<\/p>\n
Get-childitem -recurse # to check for the file\nif($condition){<#do something#>} # if statement so you validate\nsend-mailmessage # to send the email\n<\/code><\/pre>\nand here is how to schedule the task for every hour:<\/p>\n