{"id":41,"date":"2019-09-03T16:45:16","date_gmt":"2019-09-03T16:45:16","guid":{"rendered":"https:\/\/www.practicalpowershell.com\/post\/drop-folder-powershell"},"modified":"2020-03-08T05:29:45","modified_gmt":"2020-03-08T05:29:45","slug":"drop-folder-powershell","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/","title":{"rendered":"Drop Folder PowerShell"},"content":{"rendered":"<p>Drop folders can be used for a lot of things.  Files placed in these folders can be processed by PowerShell for whatever purpose they were defined for.  Sample usages of a Drop Folder:<\/p>\n<p><em>(1) CSV file containing a list of users &#8211; Used to verify AD information<br \/>\n(2) Txt file containing tweets to be sent out via PowerShell and a<br \/>\n(3) CSV file with a list of mailboxes to migrate to another server or to Office 365 <\/em><\/p>\n<p>The author has used a drop folder for each of the above sample tasks in order to service a client request.  Some of these will require an automated process, where others might need to be more manual.  Some keys to these examples: <\/p>\n<p><em>(a) Check for files &#8211; before proceeding, see if there are any files.  No files, exit script.  Files exist, move to the next step.<br \/>\n(b) Put in a cleanup option at the end to remove any files that are no longer needed.<br \/>\n(c) Log Log Log &#8211; log changes, cmdlets, etc to keep track of the progress of the script. <\/em><\/p>\n<p>The below example will look for text files in a $Path directory.  Then if files are found, content will be read and tweeted out.  Files that are found will also be deleted.  If no files are found, no tweet is sent. <\/p>\n<p>Example Tweet Txt File<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n# Twitter File Drop Path<br \/>\n$Path = &#039;C:\\Twitter\\TwitterDrop&#039; <\/p>\n<p># Import twitter module<br \/>\nImport-Module MyTwitter <\/p>\n<p># Check for files:<br \/>\n$FileCheck = Get-ChildItem $Path <\/p>\n<p># If files are present, proceed<br \/>\nIf ($Null -ne $FileCheck) {<br \/>\n    $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n    $Line = &quot;$Date,Files found &#8211; proceeding to tweet each file found.&quot; | Out-File $LogDestination -Append<br \/>\n    $FileNames = $FileCheck.Name<br \/>\n    Foreach ($FileName in $FileNames) {<br \/>\n        $FullName = $Path+&#039;\\&#039;+$FileName<br \/>\n        $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n        $Line = &quot;$Date,Processing the $FileName file to be tweeted.&quot; | Out-File $LogDestination -Append<br \/>\n        $Content = Get-Content $FullName<br \/>\n        Try {<br \/>\n            # Write-Host &quot;Send-Tweet -Message $Content -ErrorAction STOP&quot;<br \/>\n            Send-Tweet -Message $Content -ErrorAction STOP<br \/>\n            $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n            $Line = &quot;$Date,Success &#8211; Tweet in file &#8211; $FileName &#8211; with tweet &#8211; $Content &#8211; sent via twitter!&quot; | Out-File $LogDestination -Append<br \/>\n        } Catch {<br \/>\n            $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n            $Line = &quot;$Date,Failed &#8211; Tweet in file &#8211; $FileName &#8211; with tweet &#8211; $Content &#8211; failed to send via twitter!&quot; | Out-File $LogDestination -Append<br \/>\n        }<br \/>\n        Try {<br \/>\n            Del $FullName -ErrorAction STOP<br \/>\n            $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n            $Line = &quot;$Date,Success &#8211; removed the $FileName file.&quot; | Out-File $LogDestination -Append<br \/>\n        } Catch {<br \/>\n            $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n            $Line = &quot;$Date,Failed to remove the $FileName file.&quot; | Out-File $LogDestination -Append<br \/>\n        }<br \/>\n    }<br \/>\n} Else {<br \/>\n    $Date = Get-Date -Format &quot;MM.dd.yyyy-hh.mm-tt&quot;<br \/>\n    $Line = &quot;$Date,No files found in Drop folder to process for tweets.&quot; | Out-File $LogDestination -Append<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nThe PowerShell module I am using for the above tweeting is <strong>MyTitter<\/strong> by Adam Bertram and more information on the module can be found here &#8211; <a href=\"https:\/\/adamtheautomator.com\/twitter-module-powershell\/\">https:\/\/adamtheautomator.com\/twitter-module-powershell\/<\/a>. ** The above code sample is provided as-is for you to learn from.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Drop folders can be used for a lot of things. Files placed in these folders can be processed by PowerShell for whatever purpose they were defined for. Sample usages of a Drop Folder: (1) CSV file containing a list of users &#8211; Used to verify AD information (2) Txt file containing tweets to be sent [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Drop Folder PowerShell - Practical PowerShell<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practicalpowershell.com\/drop-folder-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Drop Folder PowerShell - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"Drop folders can be used for a lot of things. Files placed in these folders can be processed by PowerShell for whatever purpose they were defined for. Sample usages of a Drop Folder: (1) CSV file containing a list of users &#8211; Used to verify AD information (2) Txt file containing tweets to be sent [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/drop-folder-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-03T16:45:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-08T05:29:45+00:00\" \/>\n<meta name=\"author\" content=\"damian\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"damian\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"Drop Folder PowerShell\",\"datePublished\":\"2019-09-03T16:45:16+00:00\",\"dateModified\":\"2020-03-08T05:29:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/\"},\"wordCount\":516,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/\",\"name\":\"Drop Folder PowerShell - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"datePublished\":\"2019-09-03T16:45:16+00:00\",\"dateModified\":\"2020-03-08T05:29:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/drop-folder-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Drop Folder PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/\",\"name\":\"Practical PowerShell\",\"description\":\"PowerShell books written by experts\",\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practicalpowershell.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\",\"name\":\"damian\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"caption\":\"damian\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Drop Folder PowerShell - Practical PowerShell","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Drop Folder PowerShell - Practical PowerShell","og_description":"Drop folders can be used for a lot of things. Files placed in these folders can be processed by PowerShell for whatever purpose they were defined for. Sample usages of a Drop Folder: (1) CSV file containing a list of users &#8211; Used to verify AD information (2) Txt file containing tweets to be sent [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/","og_site_name":"Practical PowerShell","article_published_time":"2019-09-03T16:45:16+00:00","article_modified_time":"2020-03-08T05:29:45+00:00","author":"damian","twitter_card":"summary_large_image","twitter_misc":{"Written by":"damian","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"Drop Folder PowerShell","datePublished":"2019-09-03T16:45:16+00:00","dateModified":"2020-03-08T05:29:45+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/"},"wordCount":516,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/drop-folder-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/","url":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/","name":"Drop Folder PowerShell - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"datePublished":"2019-09-03T16:45:16+00:00","dateModified":"2020-03-08T05:29:45+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/drop-folder-powershell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/drop-folder-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"Drop Folder PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/practicalpowershell.com\/#website","url":"https:\/\/practicalpowershell.com\/","name":"Practical PowerShell","description":"PowerShell books written by experts","publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practicalpowershell.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb","name":"damian","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","caption":"damian"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":2,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":272,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/41\/revisions\/272"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}