How To Execute PowerShell Scripts With Pulseway

choubertsprojects

VPN offers!

1. NordVPN

2. Surfshark

3. ExpressVPN

PowerShell is a command-line shell and scripting language built on Windows. If you use PowerShell regularly, Pulseway can help you speed up your workflow by executing scripts asynchronously. How does it work? Let’s take a look!

The “pulseway scripts” is a tool that allows users to execute PowerShell scripts with Pulseway. The tool can be used to automate tasks in the system, such as sending notifications or making changes to files.

How To Execute PowerShell Scripts With Pulseway

Pulseway is the sponsor of this blog article.

So you’ve written a fantastic PowerShell script that will save you a ton of time. You pat yourself on the back after hitting Save in your editor. This script is supposed to run on numerous servers, so you settle down to make it happen only to discover it’s not as simple as you thought.

Executing PowerShell scripts against remote systems may cause challenges with system targeting, remote connection, and enhancing performance by running them in parallel. Fortunately, I’ve recently been working with a product called Pulseway that helps with this problem.

In this Pulseway review, I’ll show you how to use the Pulseway software to run PowerShell scripts against a set of remote servers.

In the TechSnips server environment, we’re currently experiencing a handful of challenges. The first is that the print spooler service on all of our servers must be restarted every night. Second, our contributors maintain their PowerShell ISE sessions active 24 hours a day, 7 days a week. I’ve already built several scripts to deal with these difficulties, and I’ll utilize Pulseway to execute them across numerous computers automatically.

So go to Automation in Pulseway, and then start with Scripts.

Pulseway's Script menu itemPulseway’s Script menu item

You’ll find a built-in category here by default, but you’ll want to create your own to store your scripts in.

Pulseway has a script category.Pulseway has a script category.

I’m going to create my own category, which I’ll name Custom. Once the category has been established, we can right-click on it and choose Create Script. Make a name for your script. Restart Print Spooler Service will be my first.

In Pulseway, create a new script.In Pulseway, create a new script.

Then I’ll go to the Windows tab and enable Enabled, after which I’ll be able to choose my script type. This sets the default to PowerShell, which is exactly what I want. If you require a VBScript or batch file, however, you must change the script type.

I’ll leave PowerShell alone and start my script. The script I’m using here stops the service, waits a few seconds, and then restarts the service.

I’ll click Save Script when I’m satisfied with everything here.

-Seconds—Start—Sleep—Seconds—Seconds— 5 Stop-Service’spooler’ -Name Start-Service -Name’spooler’ Start-Sleep -Seconds 3

After I’ve saved it, I’ll return to Scripts and create my second script to address my second problem. This is going to be the last of PowerShell ISE sessions. However, there is one caveat: I don’t want to terminate any PowerShell ISE processes that belong to admin users; I’ll put that in the description.

I’ll go back to the Windows tab and make sure I’m on PowerShell before adding my script.

-Seconds—Start—Sleep—Seconds—Seconds— 5 Get-CimInstance Win32 Process -Filter “name = ‘powershell ise.exe’” $PsProcs = Get-CimInstance Win32 Process -Filter “name = ‘powershell ise.exe’” $Proc in $PsProcs) foreach $Owner = Invoke-CimMethod -InputObject $Owner = Invoke-CimMethod -InputObject $Owner = Invoke-Cim if ($Owner.User -notlike ‘admin*’) $Proc -MethodName GetOwner -Force Stop-Process -Id $Proc.ProcessId

This script will obtain all of the PowerShell ISE processes, walk through them, check for the owner using the GetOwner method, and then kill the process if the owner doesn’t start with the word “admin.” To confirm, I’ll click Save Script.

Now that both of my scripts are complete, we must integrate them into a job. Select Tasks and Create Task from the Automation menu.

Pulseway task creationPulseway task creation

Before we go ahead and upload our real scripts, we have a few more choices to choose from. For example, I’d want to be notified whether or not this job is executing successfully, therefore I’ll enable notification if the task fails. And I’ll keep it at a high setting, but you may tweak it as required.

I’d also want to be notified if the work is completed satisfactorily. However, I won’t leave it at normal since I don’t want my phone to make a noise if this works, and I already have my low notifications turned off, so I’ll simply put it to low.

Notifications from PulsewayNotifications from Pulseway

The default scope is All Systems, but if you’ve previously defined a different scope, you may choose it here to restrict the systems on which this will operate. And if you don’t already have a scope but want to put one up right away, there’s a helpful button called Create Scope that will allow you to do so.

I’m OK with my job targeting all systems, therefore I’m not going to create a scope for this.

Setting the scope of a script in PulsewaySetting the scope of a script in Pulseway

But, since I want this to happen every night, I’d want to be able to schedule it. I’ll set the Repeats option to Daily, which means it’ll happen once a day. I’d want this to start at 1:00 a.m., so I’ll modify the date to tomorrow and the time to 1:00 a.m.

In conclusion, I can certify that my daily routine is exactly what I desire, beginning tomorrow at 1:00 a.m.

In Pulseway, you may create a timetable.In Pulseway, you may create a timetable.

When I’m satisfied, I’ll click Save and return to the top of the page to choose Scripts.

Setting up a task to execute a scriptSetting up a task to execute a script

Choose your category from here; mine was Custom. I’ll include both of the scripts we set up at the beginning. My print spooler service will come first, followed by my ISE processes termination routine.

Now, they do run in sequence, so make sure you place them in the correct order if the order is crucial. Save the assignment after you’re satisfied with it.

Script task creationScript task creation

Returning to Tasks, you’ll see a little alarm clock indicator inside the cog, indicating that this is a scheduled task. We can, however, run this on demand to get a better look at what’s going on. I’ll enter View mode…

The job of viewing the scriptThe job of viewing the script

…and then press the Start button. We can monitor its progress while it runs. So we can see that it’s aiming for four systems, has finished zero of them so yet, and the task is still going.

Examining the job's specificsExamining the job’s specifics

I’m presently verifying my print spooler service in ISE, and you can see that it was stopped and then resumed automatically.

Output from a Pulseway script taskOutput from a Pulseway script task

As a result, we know that this task ran properly on my PC. We can see from the execution history that the whole task was successful, which means it executed on the other three servers in the TechSnips server environment. I can go further into this and examine the systems, and I can see that each one was finished effectively.

And, if any failures occurred, I could go deeper and examine the output for each individual task. I anticipate the output to be blank since all of them were successful, but if there were any mistakes, they would be shown here.

Information about the positionInformation about the position

This was an excellent example of how we can use Pulseway to aid with PowerShell script distribution.

Pulseway is accessible at pulseway.com if you want to learn more about it and try it out.

The “pulseway bitlocker” is a PowerShell script that allows users to execute commands on their BitLocker encrypted drives. This script can be used with Pulseway, which is an open source tool for Windows.

Frequently Asked Questions

How do you execute a PowerShell script?

A: PowerShell is a scripting language that allows you to perform batch file-like operations. You can execute your script by clicking on the Start button and then typing in the name of your script, which will be displayed at the top right corner of your screen.

How do I run a PowerShell command in Jenkins?

A: PowerShell lets you run commands by first executing them in the Windows command prompt.

Can I run a PowerShell script from the command line?

A: Yes. To run a PowerShell script from the command line, you would type powershell in your terminal and then enter your commands after that.

Related Tags

  • powershell install 7zip
  • script to create vpn connection windows 10
  • powershell check if vpn connection exists
  • pulseway forum
  • pulseway feature request