{"id":4069,"date":"2016-06-18T13:14:08","date_gmt":"2016-06-18T13:14:08","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=4069"},"modified":"2016-06-18T13:14:08","modified_gmt":"2016-06-18T13:14:08","slug":"powershell-foreach-object-gotcha","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/powershell-foreach-object-gotcha\/","title":{"rendered":"Powershell ForEach-Object gotcha!"},"content":{"rendered":"<p>Are you serious Powershell !!!!?<\/p>\n<p>Okay, now I&#8217;ve got that out of the way, I wrote a little Powershell command to delete the *.deleteme files as well as the folders they refer to that Nuget occasionally seems to leave behind when updating packages.<\/p>\n<p>So I developed the script on the command line and all looked good so decided to turn it into a function to add to $profile.<\/p>\n<p>The function kept failing with the error &#8220;Supply values for the following paraneters: Process[0]&#8221;.<\/p>\n<p>This appears because my foreach looked like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nforeach \r\n{ \r\n   \/\/ some functionality\r\n}\r\n<\/pre>\n<p>and even though we think that the curly brace is the block (as it is in C#) it appears we need to place the first curly brace on the same line as the foreach, thus<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nforeach { \r\n   \/\/ some functionality\r\n}\r\n\r\nHere's the script, when it was completed\r\n\r\n&#x5B;code language=&quot;csharp&quot;]\r\nfunction Delete-DeleteMeAndFolder\r\n{\r\n   ls &quot;*.deleteme&quot; | \r\n   foreach { \r\n      rm -Recurse -Force $_.Name.Replace(&quot;.deleteme&quot;, &quot;&quot;)\r\n      del $_.Name\r\n   }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Are you serious Powershell !!!!? Okay, now I&#8217;ve got that out of the way, I wrote a little Powershell command to delete the *.deleteme files as well as the folders they refer to that Nuget occasionally seems to leave behind when updating packages. So I developed the script on the command line and all looked [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[118],"tags":[],"class_list":["post-4069","post","type-post","status-publish","format-standard","hentry","category-powershell"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/4069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=4069"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/4069\/revisions"}],"predecessor-version":[{"id":4076,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/4069\/revisions\/4076"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=4069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=4069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=4069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}