Run PowerShell script on remote computers from a Web GUI

In this post, I will show you how to execute or schedule your PowerShell scripts to remote computers from a Web platform called Rundeck. You will be also able to run simple commands.

I will do presentation for the French PowerShell User Group about Rundeck and PowerShell the 12 of March, click here to subsribe.

What is it ?
Rundeck is a web solution that allows you to run job remotely on computers through WinRM.
To resume, you have:
- The rundeck server 
- Your remote computers (stored in a conf file, xml, yam, json)
- The web GUI that allows you to run script or command on computers located in the config file.

We can imagine a script that will gather all computers from your AD, of from an OU and add them in the conf file. This way, you will be able to manage all those computers.

Rundeck is a solution based on Java and can be installed on Linux or Windows.
Differents solution are available, as you can see below:

I won't explain how to install and configure it in this post but in another one.
You can find more informations on the Rundeck website here.

Is the community version ok ?
In my case i use the Community version.
My client, used it for one year, and managed about 1000 computers with it.
With the this version you can run command or script easily on your remote computers. Youy can manage as much computers as you want.

Why the Enterprise version ?
My client now use the Enterprise version.
I will expmain in differents points why this one is cool.
1 / This version, can be installed very easily on Windows.
2 / More plugins are available:
- Run a script directly from GitHub
- Manage Azure VM
- Manage VM from VMWare
- Plugin for Service Now
- Plugin for JIRA
3 / It offers you some better dashboard

How it looks like ?
The main GUI looks like as below.
- A login part
- A main part
- A sidebar

Of course, you can easily add your own logo as below:

The first page displays all your projects.

What is a project ?
A project is the main organization of your jobs.
It will be used to organize your jobs. We can define a project like a main folder that will contains your scripts.

You can for instance have a project per environment:

A project will contain your jobs.
If you click on a project all your jobs will be displayed, as below.

What is a job ?
A job is the part that will be executed on the remote computers.
It can run for instance a script, copy content, a local command, a script from Github...
To configure a job, click on your job then click on Edit the job.

To add a script, or an action in your job, you will have to add a step.
You can run one or multiple scripts by using multiple steps, for instance:
- A step to check if connection with remote computers is OK
- A step to query remote computers BIOS settings and export to CSV 
- A step to copy CSV from each computers to your local computers

You can also add error handling in order to say, hey boy the first step, check connection is KO, so don't continue to the other steps.
To add a step, just click on the button Add a step :-)
Now differents kinds of steps are available.
- Command: To execute a command on the remote computer. 
- Script inline: To add directly your script content in a bloc. In my case I use this part.
- Job reference: To run another Job
- Command to execute on the server directly

To use the script inline part proceed as below:
1 / Open the advanced part
2 / Copy your script content in the first bloc
3 / Add arguments if neeeded (we will add argument for option later in the post)
4 / In the Invocation String field type: Powershell.exe -executionpolicy bypass 
5 / In the file extension part type: ps1
6 / In the Step Label part, type the name of the step.
7 / click on Save of course

The job reference part may be really useful. 
For instance if you have to run to schedule a script that should be run on different countries with different timezone at 4PM.
In this case, we will create one job per country but instead of adding the script in each job we will call a job reference. 
This way, if you have to add or change something in the script you won't have to modify each job, but just the reference job.

Another great part of the job is the Option part.
This one allows you to add some controls like:
- Password 
- TextBox
- Dropdown menu

For instance, you can create a job that will change status of a windows service on a remote computer.
A textbox allows you to type the service name you want to manage.
A dropdown menu allows you to choose if you want to get status of a service or start/restart/stop the service.

To add an option proceed as below:
1 / Click on Add an option
2 / Choose what you want

To add textbox 
1 / Click on Add an option
2 / Use the Option Type Text
3 / Give a name to your control, this name will be used in the argument part of your inline script, as mentioned above. In my case the name is Service_Name.
4 / Optional fields: label, description.
5 / Click on save
6 / In your inline script add the argument as below 

To add a dropdown menu
1 / Click on Add an option
2 / Use the Option Type Text
3 / Give a name to your control. In my case the name is Action
4 / In the Allowed Values part, choose List.
5 / In the TextBox type values to choose. In my case Get,Restart,Start,Stop.
6 / In the Restrictions part select Enforced from Allowed Values.
7 / In the Default Value part type the default value the use. In my case, Get.
5 / Click on save
6 / In your inline script add the argument as below:

Jobs in action
In the below example I created a Folder Windows_Management with different jobs
- Action on service
- Add user in local admin
- Check disk space
- Create local user
- Get last events

The action on service job allows me to do an action on a service on remote computers.
For instance I want to get the status of service spooler on computer 1 and 2.

The check disk space job will check the disk size on remote computers.

Command part
On the sidebar, another cool part is available.
This one, called Command allows you to execute directly a command on a remote computer.
For instance I want to get the value of the Winlogon registry on the computer toto.
1 / Select he node toto in the part node
2 / Type the command below
3 / See below the result
See below the command in action:

In the next post I will explain more about configuration and installation.

Share this

Related Posts

Next Post »

1 commentaires:

20 mars 2019 à 14:58 delete

Bonjour Damien,

Quand prévoyez-vous de mettre à disposition les sources de présentation et d'exemples que vous aviez lors de la présenation le 12 MArs?