Powershell script: how to run and write one
Table of contents:
- What is PowerShell?
- How to run and write scripts in PowerShell
- Run or write simple commands in PowerShell
- Write scripts from Windows Power Shell ISE
- Run script from Windows Power Shell ISE
- Run new scripts in Power Shell
- Run scripts already created
- Error executing script in Power Shell
PowerShell corresponds to one of the best tools of the Windows operating system, it has been available since December 2006 and is enabled for Windows XP and its later versions.
However, despite being such an interactive program, it is a bit complex to use, which is why we will mention below how you can run and write the scripts in this wizard.
Index of contents
What is PowerShell?
PowerShell is a related interface, which executes commands or instructions directly to the computer, both for the server it uses and for certain applications installed on the system.
Its main requirement is the prior installation of a resource called .NET with a version no less than 2.0, and in addition to being admissible mostly in Windows, it can also be downloaded alternately in more complex operating systems such as Linux and MacOS.
This program differs from CMD (Command Console) in that its functions are much more extensive, allowing deeper changes to be made to the system server as such and to other more specific programs.
In addition, it is more modern than the CMD and corresponds to a much more versatile tool than the latter, thanks to the type of programming language that is used in executing the commands.
How to run and write scripts in PowerShell
To execute scripts you must bear in mind that PowerShell must have full permissions on the server, this being a fundamental requirement for its use.
Run or write simple commands in PowerShell
The procedure to execute simple scripts in PowerShell is as follows:
- Go to the "Start" section of Windows. Once you are there, search for "Windows PowerShell". When the corresponding result appears, right-click on it. Then, you must click on the option "Run as administrator".
Then confirm the action in the pop-up menu that will appear.
- When you have done this, the open PowerShell program will be displayed on your PC, and you can run the commands you want.
Note: The tool allows you to place scripts in written form or paste them into the system, for this last aspect you only need to copy the command from any section of the PC and proceed to right-click on the blue menu.
Write scripts from Windows Power Shell ISE
Windows PowerShell ISE is an assistant to the PowerShell program as such, which allows creating, saving, modifying and also writing new commands in said tool.
However, for the latter, these guidelines must be followed:
- Enter "Windows PowerShell ISE" from the quick options of the "PowerShell" program. Proceed to go to the "View" section that you will notice at the top of the menu. Then select "Go to the script panel Finally, he proceeds to write the selected command.
Likewise, this tool will allow you to cut, copy or paste commands directly, although for this you must use the buttons found in the upper section of the writing menu.
In addition to this, you can overwrite a script already placed in the writing menu, but to do so you have to click "Ctrl + H" and search specifically for the command line you want to modify.
Run script from Windows Power Shell ISE
The procedure to execute a script is very simple, simply enter Windows Power Shell ISE and click "Run Script", a button found in the top menu.
The latter is green and corresponds to an arrow located in the third section of said predetermined section.
Likewise, you can go to "File" and from there click on "Execute" so that the command begins to carry out the pre-established processes.
However, this program also allows you to run only part of the Script, but to do this you must go to the third section of the quick options menu and click on “Run selection” and then specify which part of the script you want.
Run new scripts in Power Shell
Despite the fact that Power Shell is an executor program, it allows creating scripts to our liking, although to do this, the following steps must be taken into account:
- Firstly, access "Power Shell ISE" from the browser of your PC. Then, when the program is displayed on your screen, click on the "New" alternative that appears in the quick options at the top. Finally, write in the part Below is the new script to perform.
However, setting a new script only works by following the following rules:
- A code denomination must be established with the sign "#", for the purposes of modification and identification. The type of variable you want to designate must be placed: In this case, the symbol of "$" is used, then the sign of “=” And then an alternate value is set. Variables must have an identification method: This is in order to set the type created and specify the digits used in the script.
After this you have to proceed to save it, executing this procedure:
- Click on the "File" match in the upper section. Click on the "Save as" menu. Place the name you want without any pre-established signs in the "File name" box. Proceed to indicate "PowerShell Scripts (*. ps1) ” in the “ Save as type ” alternative. Finally press “ Save ” at the bottom.
Run scripts already created
If you have already created a Script and stored it in your directory, you can open it directly in Windows Power Shell ISE as follows:
- As a first step, you must access "Windows Power Shell ISE". Then, you have to click on "File" in the upper left. Then you must click on "Open…". This will take you to the designated documents of the PC, between them select double click on the script you want to use.
Error executing script in Power Shell
Sometimes, when writing a command in PowerShell as such, you will be shown a message with a problem specified in red letters, this is usually due to permission restrictions that a script set in the menu has.
However, this failure can be easily solved, although for this you must indicate a new execution policy in the tool, since this last feature protects the system from unsafe scripts.
Note: You should know that if the script has an informative logic description of little reliability, then it is recommended not to make this modification for simple computer security.
However, the procedure to be carried out in this case is simply to execute this command: Get-ExecutionPolicy, in order to see the status of the security policies.
We recommend reading the following tutorials:
Likewise, to establish new rules in this field, the following description must be used: Set-ExecutionPolicy RemoteSigned, and with this method the fault will be solved by the tool.
Toshiba encore 2 write, windows 8.1 tablet and stylus
The Japanese Toshiba has announced a new tablet with Intel Atom processor and Windows 8.1 operating system that will come accompanied by a touch pen to improve its possibilities of use.
How to know the read and write speed of a hard disk
Tutorial on how to know the reading and writing speed of a hard disk. Find out the read and write speed of USB, SSD or SD card.
Powershell: what it is and basic and 【recommended comandos commands
We explain what a powershell is and the main basic commands you need to know to start with this Windows terminal?