<div data-elementor-type="wp-post" data-elementor-id="684" class="elementor elementor-684" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-ad46661 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="ad46661" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3d79eec" data-id="3d79eec" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-669c198 elementor-widget elementor-widget-heading" data-id="669c198" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">Intro</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-f2b0fae elementor-widget elementor-widget-text-editor" data-id="f2b0fae" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Starting my journey using ConnectWise Automate, I quickly realised the most obvious way of running PowerShell scripts, natively in the ConnectWise Automate scripting language frequently results in scripts never finishing or only partly executing, I&#8217;ve spent hours troubleshooting and found the best way to run PowerShell scripts in Automate!</p><p>This info is the result of hours of my struggle! ð</p>								</div>
				</div>
				<div class="elementor-element elementor-element-5cc6bfa elementor-widget elementor-widget-heading" data-id="5cc6bfa" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">Method</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-2379d1e elementor-widget elementor-widget-text-editor" data-id="2379d1e" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>I find the best solution to creating complex scripts in ConnectWise Automate, is to avoid the in-built features as much as possible and rely as much as you can on writing text files to the computer; then having the computer run those text files as PowerShell scripts natively, (You want to avoid the built-in Automate PowerShell too).</p><p>So how do we do this?</p><p>The first step is to develop your PowerShell script (You should do this in your own testing environment and away from Automate), it will take you considerably longer to find issues in your code when trying to execute a script on Automate.</p><p>Once your PowerShell code is developed and fully tested, you should create your Automate script, so that it writes your PowerShell script as a text file (with the .ps1 extension) to the computer. I find writing to &#8216;C:\Windows\temp&#8217; to the be the best location &#8211;</p><p><img class="alignnone size-large wp-image-687" src="http://techzilica.com/wp-content/uploads/2022/09/ConnectWise-write-script-to-PC-1024x408.png" alt="Writing ConnectWise Automate PowerShell script to the PC" width="1024" height="408" /></p><p>Now you&#8217;ve got the script file written to the PC, you need to call the script and get it to execute on the PC, so the next step is executing the script file you&#8217;ve just written:<br /><img class="alignnone size-large wp-image-688" src="http://techzilica.com/wp-content/uploads/2022/09/ConnectWise-execute-script-thats-on-the-target-PC-1024x311.png" alt="" width="1024" height="311" /></p><p>Thats it! it&#8217;s really that simple, so if you&#8217;ve had issues with running PowerShell on ConnectWise Automate endpoints, try this, it should resolve all your problems!</p><p>Remember, it is really important to debug your PowerShell code before involving Automate in the process, this will save you hours.</p><p> </p><h5><a href="https://mega.nz/file/6IhGCJ7C#uwWerUSdCJ724mRzigUSH1q2VBc_WYzmpSfrQQ5BWg8">You can download my script referenced in this article here.</a></h5>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				</div>
		
The best way to run PowerShell Scripts on ConnectWise Automate
