Tuesday, June 21, 2016

How to convert PowerShell script into an exe.

Task: I want to run a script regularly on different servers.

We face this kind of tasks several times, basic examples like to find when the server was last rebooted or what are the current free spaces of all disks of a particular server and so on.

So basically I have a script to do some ‘xyz’ work and I want to use the same script in many other servers and even my team members also should be able to run it when needed. So the better way to do is converting the PowerShell script into an exe and distribute the exe to all my team members or place it in a shared location where my entire team has access.

How to convert PowerShell script to exe:


1.    To do this first you need to install ‘PowerGUI Script Editor’ if you don’t have it already.


2.    Open ‘PowerGUI Script Editor’: Start à All Programs à PowerGUI à PowerGUI Script Editor




3.    Open new page by pressing ‘Ctrl+N’. Paste the script you want to convert to exe.




4.    Execute the script by clicking ‘Play’ button which will be on top or by pressing shortcut ‘F5’. This is just to test script is working without any errors. My sample script to get last reboot date time is giving results as expected.




             Now steps to convert PowerShell script to exe

5.    Click on ‘Tools’ and select ‘Compile Script’ or shortcut for this is Ctrl+F9. Screenshot below:




6.    Once compile script window opens give the path to save the script as exe, as shown in screenshot below:




7.    Now you have the exe created for our script.


8.    Now you can run your script by just double-clicking the exe. This exe will run fine in any of the machines where PowerShell is installed.



Please share what are the steps you follow to convert your scripts to run on different servers.



Thanks VV!!

No comments:

Post a Comment