When installing a new version of the Windows operating system, novice users encounter new names of programs that they may not have heard before and the purpose of which is not clear to them. One such application is PowerShell. If it is preinstalled in the OS, then it serves something. What kind of Windows PowerShell software is this? Users often ask this question. Let's take a closer look at it.
This application is a useful tool for system administrators and developers, but for other users, especially beginners, it is of little use. Windows PowerShell is a modern, improved command line that can provide more flexible work with settings and computer management in the Windows operating system. In other words, the same command line with additional features.
What is Windows PowerShell
Windows PowerShell is a scripting language and command-line program for executing these scripts. This language was released in 2006 as part of the second service pack for Windows XP and since then PowerShell has been part of all Microsoft operating systems. In 2008, the second version of this language appeared, and starting from Windows 7 it is this version that is used. Files with Windows PowerShell scripts have a PS1 extension and can be run as familiar BAT and CMD files.
Windows PowerShell is a scripting language designed primarily for Microsoft business customers who need powerful tools to automate the tasks of managing Windows-based servers and computers. The .NET platform, developed by Microsoft since 2002, was used as the basis for this language.
Windows PowerShell allows you to automate a wide variety of tasks. With it you can manage files, services, processes, accounts and settings. The PowerShell language understands many of the commands found in the regular Windows Command Prompt (CMD), but it also has its own language consisting of its own commands, which are called cmdlets.
Cmdlets (in English cmdlets) are formed according to the Verb-Noun rule, for example, Get-Help. You can learn the basics of Windows PowerShell using Help (the Get-Help cmdlet). For general information, simply enter the command “Get-Help”; for help about a specific cmdlet, enter “Get-Help Cmdlet-name”. For example, if we enter the command “Get-Help Get-Process”, we will get help about the Get-Process cmdlet.
Working with the script
When creating algorithms, Windows PowerShell ISE is often used, a specially created mechanism, including for using scripts. In it, under the name “Unnamed 1.ps1”, the body of the code . Let's look at a simple example: "WMID WebMoney" in the name, set conditionally "wmid", save the file in the root of drive C. To start, you will need to enter the directory using the command "cd C:\" the file name should be in the following key: ".\ wmid". It is noteworthy that the scripts can also be launched from the OS command line, but to do this you need to change the path to it: “powershell.exe C:\ wmid.ps1”. It is important to remember that executing scripts is prohibited by default; to obtain permission for such actions, you must set the Set-ExecutionPolicy command.
How to run a Windows PowerShell program
The Windows PowerShell program can be launched in different ways. The easiest option is to simply use the search in the Start menu. To do this, open the Start menu, enter the search query “Windows PowerShell”, and then open the found program.
You can also open the Run menu using the Windows key combination-R and enter the command “powershell”.
In Windows 10, PowerShell can be launched from any folder. To do this, click on the "File" button in the upper left corner of Explorer and select "Run Windows PowerShell."
Uninstalling a program
Microsoft PowerShell is a system component, so in principle it cannot be removed. Of course, if you really want to, you can use our article and remove this system component, but this can lead to system inoperability, so is not recommended .
Although it is worth noting that sometimes it is necessary to remove Windows PowerShell 1.0 as the operating system may not update due to this item. You can do it like this:
- We launch a system search and enter appwiz.cpl.
- In the window , select – View installed updates.
- We look for the required component in the list of updates, usually it is KB928439 and delete it.
Windows PowerShell, even with a big stretch, cannot be called a simple and accessible program; it is difficult to understand, and it will not be possible to master it in a short period of time. But given the fact that it was not created for programmers, but for novice users, it is not as incomprehensible as it might seem. The obvious advantage of the shell is its convenience and automated process, and all you need is to understand the intricacies.
How to use Windows PowerShell
As we have already said, using the PowerShell program you can automate many routine tasks in the Windows operating system. As an example, we will demonstrate some of the capabilities that this tool has to make it clear how to use it.
Emptying the Trash. There is a special cmdlet for clearing the recycle bin called “Clear-RecycleBin”. This cmdlet is useful when writing scripts for servicing computers. When you run the cmdlet, you must specify the drive on which you want to empty the Recycle Bin. Example:
Clear-RecycleBin c:
The screenshot below shows how this cmdlet is executed. After entering the “Clear-RecycleBin c:” command, a confirmation message appears. In order to continue executing the cmdlet, enter the letter “Y” and press Enter.
If you add "-Force" to the "Clear-RecycleBin c:" cmdlet, the recycle bin will be cleared without asking for confirmation. Screenshot below.
Archiving files. For archiving and unpacking files, the “Compress-Archive” and “Expand-Archive” cmdlets are provided. For example, in order to archive the “C:\test\” folder into the “C:\archive\test2.zip” archive, you need to run the following cmdlet:
Compress-Archive -LiteralPath C:\test\ -DestinationPath C:\archive\test2.zip
As a result of executing the command shown above, a file “test2.zip” will appear in the “C:\archive\” folder, in which the contents of the “C:\test\” folder will be archived.
The Most Useful PowerShell Cmdlets
The shell contains their impressive catalog, represented by hundreds of commands. It is not possible to remember all these names and the properties attached to them. But this doesn’t need to be done; most of them are used extremely rarely, or even not applicable at all in practice. You should pay attention only to the most important, practical, and useful functions.
The most useful to use:
- Get-Help – reference book on the purpose of cmdlets and general shell properties;
- Update-Help - download and install updated help data;
- Get-Command – search engine for required commands, with auto-filling of the line;
- Get-Alias – reflects established aliases, in a general list or with specifics;
- Get-PSDrive – represents running drives and processes occurring on them;
- Install-WindowsFeature – role-based and component installer;
- Uninstall-WindowsFeature – role-based and component uninstaller;
- Get-History – is responsible for returning command lists executed at login.
- $hversion – returns the utility version
What is FPS in games
Variables:
- Get-Variable – shows a list of all variables taking into account their values;
- New-Variable – used to configure newly created variables;
- Set-Variable – sets new values if they are not in the list;
- Clear-Variable – content uninstaller that saves the image;
- Remove-Variable is an uninstaller for cmdlets and their components.
Formatting:
- Format-List – extended reference book;
- Format-Table – displays a table of the results of individual commands;
- Format-Wide - an extended table of the results, with the properties of individual objects.
Internet:
- Enable-NetAdapter – to enable the adapter;
- Rename-NetAdapter – sets a new name and representation;
- Restart-NetAdapter – used to restart;
- Get-NetIPAddress – provides proxy server configuration information;
- Set-NetIPAddress – sets a new configuration for the proxy server;
- New-NetIPAddress – creates and configures a proxy server;
- Remove-NetIPAddress – proxy server uninstaller;
- New-NetRoute – used to make additional entries;
- Get-NetIPv4Protocol - provides data over the IPv4 protocol;
- Get-NetIPInterface - Reflects the properties and characteristics of the IP web interface.
Elements:
- Get-Item - receives items at a given path;
- Move-Item – to move items to other folders;
- New-Item – used for creation and design;
- Remove-Item – uninstaller of marked items;
- Get-Location – Shows the current location.
Background jobs:
- Start-Job – launches;
- Stop-Job – stops work;
- Get-Job – opens a list;
- Receive-Job – provides information about the results;
- Remove-Job – uninstaller of background tasks.
Objects:
- Measure-Object – used to calculate numerical aggregation parameters;
- Select-Object – for selection indicating specific properties;
- Where-Object – reflects conditions regarding selection by value and properties.
Services and processes:
- Get-Process – shows information about active PC processes;
- Start-Process – launches on a PC;
- Stop-Process - stops the work of selected ones;
- Get-Service – provides information about active services;
- Restart-Service – performs a restart;
- Start-Service – used to connect the selected ones;
- Stop-Service – pauses the process;
- Set-Service – changes service properties and connection mode.
Computer and system:
- Restart-Computer – used to restart the OS;
- Checkpoint-Computer - to create a system recovery copy for a PC;
- Restore-Computer – responsible for launching the restored system;
- Remove-Computer - uninstalls a local PC from a domain name;
- Clear-EventLog – clears the list of log entries.
Content:
- Get-Content – receives the contents of various elements;
- Clear-Content - erases the content but preserves the images;
- Set-Content – used for rewriting.
What functions does PowerShell perform?
As I said above, Microsoft created this utility so that any tasks with the operating system can be performed much faster.
Let's say you want to see USB devices that are connected to your computer, so this can be done using PowerShell. You can also create one that will run in the background while you go about your business. If you notice unnecessary background processes that are loading your systems, you can disable them using PowerShell. You can also create a document that will store information about computer networks or other things. Thus, using this utility, you can easily and quickly perform time-consuming tasks, as well as create any scripts or combine several commands.
If you are a network administrator, then PowerShell will be able to help you work, for example, with Active Directory. Also, it is worth noting that the utility contains more than 100 commands. This means that it will help you solve most problems.
What is Power Shell
If someone worked hard to write the code for a product, it means that it is needed by someone, intended for someone. Most likely, an ordinary user will be able to derive minimal benefit from the presence of this software, but for a system administrator, this program is an excellent assistant.
Power Shell is a modern, standardized command line shell that provides access to more flexible management of a Windows-based computer. Essentially the same command line, but the possibilities are much wider.
Administration tool functionality
The functionality of the software is impressive. With it you can manage services, accounts, file storage, processes and even servers. The shell provides access to working with COM, NET, XML objects, running external commands, creating and executing your own scripts, and performing other operations.
The Power Shell has its own set of commands, just like the CMD, called cmdlets. The syntax of the language, definitions of cmdlets and their parameters in this program differs from the usual, although the utility is able to recognize many CMD commands.
Well-understood Power Shell commands like cd, dir, copy and the like in this shell are aliases or, as they say, aliases, serving simply for convenience. Example: The dir command entered by the user to view the file system corresponds to the Get-ChildItem cmdlet.