{"id":561,"date":"2016-01-18T12:13:51","date_gmt":"2016-01-18T12:13:51","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=561"},"modified":"2016-01-18T12:13:51","modified_gmt":"2016-01-18T12:13:51","slug":"script-too-complicated","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2016\/01\/script-too-complicated\/","title":{"rendered":"Script too Complicated"},"content":{"rendered":"<p>Sometimes, an error can\u00a0really make you:<\/p>\n<p><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2016\/01\/futurama-fry-should-i-lol-or-roflmao.jpg\" rel=\"attachment wp-att-563\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-563\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2016\/01\/futurama-fry-should-i-lol-or-roflmao-150x150.jpg\" alt=\"futurama-fry-should-i-lol-or-roflmao\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>Look at this one:<\/p>\n<blockquote><p>At line:1 char:1<br \/>\n+ &amp; { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessa &#8230;<br \/>\n+ ~<br \/>\n<strong>Processing was stopped because the script is too complex.<\/strong><br \/>\n+ CategoryInfo : ParserError: (:) [cleanFolder], ParseException<br \/>\n+ FullyQualifiedErrorId : ScriptTooComplicated,cleanFolder<\/p><\/blockquote>\n<p>When Powershell tells you your script is too complex, you know you&#8217;re coding an awesome script but that you&#8217;ve either made a mistake or are running into some builtin limit. Finding documentation about this error is hard, but a reply on a forum somewhere pointed me to recursive functions.<\/p>\n<p>Yes, I was using a recursive function in this script. The script itself was started by the Start-Job function in a &#8216;main&#8217; parent script. If I ran the child script seperately on its own, it had no issues and ran fine.<\/p>\n<p>Start-Job apparently gets you into trouble when you&#8217;re using recursive functions and the recursion level becomes too deep. I ended up using Runspaces instead to avoid this issue altogether, and noticed the resulting script was\u00a0faster and more stable as well.<\/p>\n<p>Lesson: <a href=\"http:\/\/www.get-blog.com\/?p=189\" target=\"_blank\">runspaces<\/a> are superior to <a href=\"https:\/\/technet.microsoft.com\/nl-nl\/library\/hh849698.aspx\" target=\"_blank\">Start-Job<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, an error can\u00a0really make you: Look at this one: At line:1 char:1 + &amp; { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessa &#8230; + ~ Processing was stopped because the script is too complex. + CategoryInfo : ParserError: (:) [cleanFolder], ParseException + FullyQualifiedErrorId : ScriptTooComplicated,cleanFolder When Powershell tells you your script is too complex, you know you&#8217;re &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2016\/01\/script-too-complicated\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Script too Complicated<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[39],"tags":[],"class_list":["post-561","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}