Computers Windows Internet

Windows PowerShell what is this program. What is Windows PowerShell - how to start it and use basic commands What is PowerShell

Many of the instructions on this site suggest starting PowerShell as one of the first steps, usually as an administrator. Sometimes in the comments there is a question from novice users about how to do this.

If your computer is running Windows 10, then perhaps even more quick way open PowerShell - click right click mouse on the "Start" button and select the desired menu item (there are two items at once - for a simple launch and as an administrator). The same menu can be invoked by pressing the Win + X keys on the keyboard.

Note: if in this menu instead of Windows PowerShell you have a command line, then you can replace it with PowerShell, if you wish, in Settings - Personalization - Taskbar, enabling the item "Replace command line with Windows Powershell" (in the latest versions of Windows 10 option is enabled by default).

Starting PowerShell Using the Run Dialog Box

Another easy way to start PowerShell is to use the Run window:

  1. Press the Win + R keys on your keyboard.
  2. Enter powershell and press Enter or Ok.

In this case, in Windows 7, you can set the mark to run as administrator, and in the last Windows versions 10, if you hold down the Ctrl + Shift keys when you press Enter or Ok, then the utility will also run as administrator.

Video instruction

Other ways to open PowerShell

Not all of the ways to open Windows PowerShell are listed above, but I'm sure there will be enough of them. If not, then:

Also, it happens, they ask, what are PowerShell ISE and PowerShell x86, which are found, for example, when using the first method. My answer is PowerShell ISE - PowerShell Integrated Scripting Environment. In fact, with its help you can execute all the same commands, but, in addition, it contains additional features that make it easier to work with PowerShell scripts (help, debugging tools, color markup, additional hotkeys, etc.). In turn, x86 versions are needed if you work with 32-bit objects or with a remote x86 system.

PowerShell 5.0 ships with Windows 10, but for previous operating systems, the new version was released as part of Windows Management Framework 5.0 only at the end of February, and on the second try. Today I'm going to talk about some of the new features, but I'll start with why you might want PowerShell.

Why do you need PowerShell

There is no point in learning PowerShell just like that, and this is true for any language - scripting, software, and even human. Like many Microsoft solutions, PowerShell is done with a business in mind to automate the tasks of managing PCs and servers in organizations.

At the heart of the scripting language is the powerful .NET programming platform, so PowerShell extends beyond administration.

Once I needed to delete one column from many Excel 2013 workbooks. Manual work was sickening, and googling did not give a ready-made solution. I created a thread on the forum (yes, I sometimes ask questions on OSZone too :). Any language was fine for me, but the solution unexpectedly turned out to be on PowerShell. As it turned out, you can load Excel as a COM object and manipulate it further.

Subsequently, I have repeatedly used a modification of that script for automatic update dozens of Excel workbooks pulling data from other files. It saved me a lot of time and effort.

I think the idea is clear, and you can already move on to the new PowerShell 5.0.

8 useful features

Syntax highlighting

The new console is much easier to navigate!

The red color and line numbering, however, are from a different opera.

Search in history in two directions

Keyboard shortcuts: Ctrl + R and Ctrl + S
Cmdlets: Get-PSReadlineKeyHandler and Set-PSReadlineKeyHandler

Like CMD, PowerShell has a session history with navigation arrows, a Get-History displays the log by analogy with F7. Full list the keyboard shortcuts associated with the log can be output like this:

Get-PSReadlineKeyHandler | ? ($ _. function -like "* hist *")

Two new history search functions have appeared in the results, which are shown in the image below. It works very simply.


Unlike Get-History, which contains the history of the current session, this log is maintained globally and is saved when the window is closed.

Thanks for the tip to Anton Drovosekov and Konstantin Sidyakin from our VK group.

Create connections, symbolic links, and hard links

Cmdlets: New-Item, Remove-Item, Get-ChildItem

I have enough stories in my blog, so I couldn't ignore the ability to create them in PowerShell.

# Symbolic link to New-Item -ItemType SymbolicLink -Path C: \ test \ MySymLinkFile.txt -Target C: \ test \ 1.txt # Symbolic link to New-Item -ItemType SymbolicLink -Path C: \ test \ MySymLinkFolder -Target C: \ Windows \ # Hard link to file New-Item -ItemType HardLink -Path C: \ Test \ MyHardLinkFile.txt -Target C: \ test \ 1.txt # New-Item connection -ItemType Junction -Path C: \ Temp \ MyJunctionDir -Target C: \ Windows

Honestly, the command syntax is mklink it's easier to remember, so it can turn out faster like this:

Iex "mklink / d C: \ test \ MySymLinkFolder C: \ Windows"

Creating a temporary file

Cmdlet: New-TemporaryFile

In scripts, you often need to create a temporary file in order to drop some information there. The new cmdlet is designed to do just that.

# Create a temporary file New-TemporaryFile # Create a temporary file and get its full path $ tmpfile = (New-TemporaryFile) .FullName $ tmpfile

I rarely do a clean install of the main system, but on a VM it happens regularly. And OneGet is very handy for quick auto-installation of a key set of programs.

Note. You can use this module without installing WMF 5.0. The module preview for PS 4.0 and 3.0 is available separately in March 2016, and for more recent searches in the Download Center for PackageManagement PowerShell Modules Preview.

Installing programs

This example installs four programs and a complete set of utilities from the Chocolatey repository. The first three commands are executed once, and the policy change must be confirmed. The fourth command silently installs the listed programs, and the fifth just saves time.

# Allow installation of signed packages from the Internet Set-ExecutionPolicy RemoteSigned # Install Chocolatey Provider Get-PackageProvider –Name Chocolatey -ForceBootstrap # Make Chocolatey trusted Set-PackageSource -Name Chocolatey -Trusted # Install Programs Install-Package NotepadPlusPlus, vlc, firefox, filezilla, sysinternals -Verbose -Force -ProviderName chocolatey # Add sysinternals path to PATH setx PATH "$ env: path; C: \ Chocolatey \ bin" -m

The vendor downloads to C: \ Chocolatey \ lib a package based on the chocolateyInstall.ps1 script. It downloads the program installer from the official site to the% temp% \ Chocolatey folder and runs it in silent installation mode. The simplest example is Notepad ++.

Install-ChocolateyPackage "notepadplusplus" "exe" "/ S" "https://notepad-plus-plus.org/repository/6.x/6.9/npp.6.9.Installer.exe"

Search programs

There are many programs in the repositories, all the most popular are definitely there.

Find-Package "* zip *", "* commander *" -ProviderName Chocolatey

Removing programs

With the removal of applications, not everything is so smooth, however.

Uninstall-Package -name filezilla

Ideally, uninstalling a package should silently uninstall the program, but implementation depends on the author of the package and the installer's capabilities. In practice, some packages do not contain scripts for uninstallation, others come up with crutches in the form of AutoHotkey scripts, and others simply launch uninstallation interactively, prompting you to end the process manually. However, if the installer is MSI, the uninstallation works fine.

Related Links for OneGet and Silent Installation:

  • A step-by-step guide to installing programs from PowerShell (Dmitry Bulanov)
  • Installer types and silent install keys (my 2005 article is quite relevant :)
  • Windows Autoinstall Site and AutoInstall Program Forum

Discussion and survey

For experienced scripters and system administrators, PowerShell 5.0 has other interesting features (for example, classes similar to object-oriented programming languages). You will find a complete list on this TechNet page (the link leads to the English version on purpose, since the Russian version does not yet contain information about 5.0).

You can mark snippets of text you are interested in that will be available through a unique link in address bar browser.

about the author

Syntax highlighting in PowerShell 5.0 is the default PSReadLine module. V previous versions you can install it and add it to the download in the profile script ($ profile variable) or load it yourself when needed

Import-module psreadline

Can you tell us more about silent installation from scripts? Not so long ago I began to use chocolatey, I really like it, especially updating all programs with one command. Until I figured out the quiet installation, I put everything in manual mode, command-confirmation-installation.

6yHTapb

the only thing for which I needed PowerShell in win 10 so far is to bypass the bug with the "properties" button not working in VPN settings connections. Set-VpnConnection -Name "Name" -SplitTunneling $ true.
By the way, Vadim. Any information on this? We are talking about a button in the properties of the VPN connection - network - IP version 4 - "properties". there you can usually uncheck the "use a gateway on a remote network" checkbox. the button itself is active, but nothing happens when pressed. that's where PowerShell helped.

Sergey Roshchin

Thank you so much for Chocolatey
on windows 7, as I understand it, does it work?

Lecron

By voting ... I use almost all the options. Some programs are portable. Part - it is installed with handles from the disk, for those who know how to update themselves or a serious revision has long been completed. Of these, part of the script. Some are new. Some are already preinstalled in the image.
Again, clients and tasks are different.

About PowerShell ... I think Microsoft missed the name. At first glance, it is not clear what happened. Command shell / processor or scripting programming language. The word Shell prompts the first, but then it is high time, since it is so cool, to make it the default, or at least promote it as the main one. But real use cases are more pushing for the second, the replacement of WSH.

  • Lecron: but then it’s high time, since it’s so cool, to make it the default, or at least promote it as the main one.

    In Win + X, you can replace CMD with PS (taskbar properties - navigation). And they have been promoting it as the main one for a long time - there is nothing new on TechNet for a long time about CMD, only PS.

    Of course, the target audience- IT professionals, but the same can be said about CMD and WSH. But I do not see any harm to the target audience of my blog. I find use of PS at home and at work, and it is not related to administration ..

    • Lecron

      I'm not talking about harm. And about the misunderstanding and the corresponding errors.
      What it is? How does Microsoft see it? Command processor, usually working in interactive mode, which is also maybe

      Working interactively in one syntax and semantics, but writing sequences of actions in others is ridiculous. This is the main problem. So deep that even you do not notice it, although you indirectly mentioned it in the article. The mklink syntax is not simpler, but more familiar. Since New-Item, with united syntax, allows you to create a lot. And now, in fact, its syntax is simpler than knowing many individual utilities, including their names.

      They kept their promise - here's a module for managing package managers, go ahead.

      Did not understand. What is a Manager Management Module?

        • Lecron

          It seems to me that this is where the dog rummaged. In providers. When there is no one-size-fits-all approach to package management. In fact, the user has to know and take into account which of the providers is used. And not only to users, but also to the maintainers.

          The feature is, as usual, focused on organizations, and MSI and MSU are fully supported.

          Lecron

          Perhaps I did not understand the full depth of this feature, which is why such stupid claims.
          Will the user need additional gestures if the owner of the repository / package changes the provider? Or will the package creator change its settings? Or does the package manager take over all of this?

          Hm ... here's a feature - take it, try it, figure it out - this will help clear up some questions. There is a supplier, he has packages in the repository. Have you removed a specific package? Then you will not be able to download it from that provider. But the already downloaded package remains locally, it can be further managed.

          Lecron

          By the way, here's another question. Is there an Update-Package command, or even better Update-AllPackage?

          Hi. Can you tell me whether it is possible to restore the boot or bios and how to do it? The loader of windows 7 pro flew off. In boot, I have already changed the settings, but the Windows do not want to boot. Earlier, Windows 8.1 was presented in the service, they stuck Windows 7 pro without my consent. Help solve the problem!

Alexey

I often heard about the chocolate bar, since I was reminded, I finally decided to test it. the result was not particularly impressive.

put in bulk a set of software already on the pc. only about 70% was found in the repository.
keys —y —accept-license —f —x — I smoked mana for just a couple of minutes, maybe I didn't understand.
the result:
software that I did not ask for: autoIT, autohotkey. why?
rolled over the old version of Acrobat Reader DC, cheat engine;
could not download dropbox virtualbox;
quiet mode did not work viber, wireshark, light alloy- I had to tick the boxes and click on;
skype removed the old one but did not install the new one.
and some of the shortcuts did not create, now you need to remember which ones.

Warnings:
- adobereader
- windjview
- firefox
- notepadplusplus
- teamviewer

then I did not understand what the mistakes were.

on a clean system in any case, you will have to download the rest of the software with your hands, or install from the archive that is no longer supported.
plus rarely, but in some places during installation, you need to select certain configurations - the composition of the packages, etc. here it is only possible with scripts for each product, which does not save much time at home. since all these options can change, and change from version to version - you need to monitor and rewrite scripts. doesn't sound very good.
if it could scan the registry and add it to the database or to the GUI software for selection, it would be easier. and so first you need to spend time compiling a list for the installation - to be sure, I punched each product to indicate the correct package name.

  • Sergey

    PS C: \ Users \ Gerald> Find-Package "* paint.net *" -ProviderName Chocolatey Name Version Source Summary ---- ------- ------ ------- paint .net 4.0.6 chocolatey Paint.NET is image and photo manipulation software designed to be used on computers tha ...

    Literally today I came across Habrahabr for the first time mentioning Chocolatey and right there in your mailing list. It seemed that this is it! I thought it would be an amazing script replacement for the auto-installation of free software from ninite.com, but alas. The relevance of the software is not supported at the paranoid level, and the problematic is described by the participants above.

    Vitaly

    I believe the UNIX philosophy is better suited for the console:


    Write programs that work together.
    Write programs that support text streams because it is a generic interface.

    • Vitaly, what is included in Windows console utility for ZIP? And this is done to simplify scripts in PowerShell, no need to go into CMD, integrated help, etc.

      • Lecron

        And why go into cmd, if both shells, and both must independently run executable files and manage their input / output?
        I do not mind the inclusion of such functionality, especially if it is done smartly, like an interface to zlib, and not another swelling of the code base - one thing in the explorer, another in the shell, and a third-party in cmd.

        Vitaly

        No, it is not included.
        But on my hosting, when I tried to use zip for the first time, I got something like “zip is not installed. Install with apt-get install zip ".

        Climb into cmd? Above said that PS should run binaries.

        Reference? In Linux, the command man% utility_name% or% utility_name% -?, The first one gives a detailed manual, the second one as a brief reference on the parameters. It seems to work everywhere.

        As a result, the command interpreter on Linux is both a simple and powerful thing, there are many alternatives, since there is nothing complicated in it, it just launches programs, controls the output stream and interprets the simplest syntax.

        strafer

        Vadim Sterkin: Vitaly, does Windows include a console utility for ZIP?

        I'm embarrassed to ask: wasn't it easier to add it than to file the built-in functionality?

  • Herz mein

    > why shell, use your own means to work with archives

    If there is such a possibility inherent in .Net classes, then why not use it? It's just a different approach than bash or cmd, which are command line interpreters. CLI. And PowerShell is more of a script debugger, IMHO.

    artem

    Lecron What it is? How does Microsoft see it? Command processor, usually working in interactive mode, which is also maybe to read commands from a file called a script? Or as a scripting language that has its own REPL? Agree, the difference is big?

    It is clear that the tasks are different. But I do not see any contradiction between them. Those. it is quite possible to cover both needs with one tool. This is what PowerShell strives for. Something turns out well, something is not very good. But the vision is clear.

    artem

    Vadim Sterkin:
    And they have been promoting it as the main one for a long time - there is nothing new on TechNet for a long time about CMD, only PS.

    It will be soon, I suppose. CMD (the shell itself) is now being relatively actively developed. Although before that, they did not touch it at all for ten years.

    artem

    Vitaly Write programs that do one thing and do it well.

    I see no contradictions. In PowerShell, each cmdlet does one thing (with rare exceptions). Whoever says that Expand-Archive can record DVDs or make coffee - let the first one throw a stone at me.

    Vitaly Write programs that work together.

    Here PowerShell does all the shells I know, because operates with objects, not text. Those. "Working together" (passing data between cmndlets) is much more efficient. No need to waste time parsing the text and trying to explain to the next command what exactly this text is.

    Vitaly Write programs that support text streams because it is a generic interface.

    Streams are supported too. And if it is the test that needs to be passed, there is no problem with that.

    That is, PowerShell follows this philosophy quite well.

    Vitaly For example, why stuff into PS "Creating connections, symbolic and hard links" with your own syntax, if you have mklink? Why is there "Creating and unpacking archives" if there is a zip and its analogues?

    Yes, because the specified cmandlets are the "analogue of zip". In fact, it is very easy to answer this claim. You just need to realize that cmdlets are not built-in shell capabilities, but that external commands. And everything immediately falls into place. It's okay that we have commands to perform some action, right? This is true for PowerShell as well as any other shell.

    Yes, there are a small number of cmdlets that come with the default shell. But ideologically, they are no different from those cmdlets that appear separately when installing the corresponding Windows components or are provided by third-party developers altogether.

    • Lecron

      artem: It's okay that we have commands to perform some actions, right? This is true for PowerShell as well as any other shell.

      Shell - how much of this word ... started to get distorted under the influence of MS.
      All the time I believed that commands do not depend on the launch environment, and that the commands built into the environment are needed only to serve the capabilities of the environment itself, and not third-party objects. Was he wrong?
      From this point of view, PS begins to resemble ACDSee and Nero.

      Vitaly

      Here PowerShell does all the shells I know, because operates with objects, not text. Those. "Working together" (passing data between cmdlets) is much more efficient.

      I doubt that all third-party utilities support these very objects. But the text is supported by any command line utility.

      You just need to realize that cmdlets are not built-in shell capabilities, but that they are external commands. AND

      Why then do these cmdlets have their own syntax? Well, it doesn't look like these are external commands.

      • artem

        Vitaly: I doubt that all third-party utilities support these very objects.

        Third-party utilities - no, of course. But third-party cmandlets are easy. I'd say that about eighty percent of third-party cmdlets are good enough to work with objects.

        If there is no cmdlet and you have to run the utility (executable file), then of course you have to feed it text as input. But the text is easy to get from the object (by expanding the desired property, for example). I understand that this sounds clever, but after gaining a critical mass of experience, it turns out completely intuitive.

        Vitaly Why then do these cmdlets have their own syntax? Well, it doesn't look like these are external commands.

        I cannot but agree with this. "Doesn't look like" is the right word :)

        As I said above, PowerShell takes some getting used to. And now I will say nasty things towards our evangelists and MVPs, but the abuse of aliases (dir instead of Get-ChildItem, md instead of New-Item -ItemType "Directory", percent sign instead of Foreach-Object or question instead of Where-Object, and so on, and also skipping parameter names in the case when the default works) only confuses untrained people. Because of this, among other things, I have been “getting used to” PowerShell for years. It seems to me that if all the example commands posted on blogs and forums contained the full syntax, then newbies would experience much less anal pain.

    In fact, I use 2 options: deploying a backup made immediately after setting up the system, or putting own assembly Windows 7, where I include all the necessary settings and programs.
    And with Win10, the package manager just has not yet mastered, although its presence is very enthusiastic.
    I used to play with different package managers for Windows, but for one reason or another, all of them were inconvenient in terms of "time to learn" / "time to manually download". It turned out to be easier to make your own assembly than to sculpt scripts.

    Evgeny Kazantsev

    A wonderful undertaking, I saw how to install a bunch of necessary progs with one script, I used ninite, I was not particularly impressed, now I use WPI downloaded from torrents, plus there is a lot more and a real auto-installation there, minus that you need to trust the author of the repack.
    I didn’t understand one thing, how to UPDATE installed programs completely automatically, what is the key basic main feature of any package manager? How to make the same notepad ++ be registered automatically by the default application without getting into the terribly inconvenient "new, they are modern" settings? How does the dependency system work, and is it even there? "

    And if you design it as a script or a function? For example like this (without checking for existence and without converting to full paths, which is necessary):

    Param ($ create, $ extract, $ path, $ zip) add-type -assembly system.io.compression.filesystem function create-zip ($ path, $ zip) (:: createfromdirectory ($ path, $ zip)) function extract-zip ($ zip, $ path) (:: extracttodirectory ($ zip, $ path)) if ($ create) (create-zip $ path $ zip) if ($ extract) (extract-zip $ zip $ path)

    Call accordingly:

    . \ test -c -p "C: \ Some \ Folder" -z "D: \ Folder \ out.zip" # To create. \ test -e -p "C: \ Some \ Folder" -z "D: \ Folder \ out.zip "# To extract

    • What does the design have to do with it? You are using .NET classes directly in your function. The cmdlet eliminates the need for nbx to refer to classes. This is the difference. Roughly the same as between a programmer and an IT professional.

      artem

      Trolleybus from a loaf of bread.jpg

      As I understand it, no one argues that functions can do anything at all :) The benefit, obviously, is that now you don't need to write a separate function specifically for this action. This means - firstly, it will be easier for people to use it (especially if they do not know how to write functions or cannot afford to import them every time), and secondly, there will be more standardization. This is an undeniable blessing. Agree, it's stupid when five scripts from five different authors require you to unpack archives, and each solves this problem a little differently. (For example, at one time the option through the undocumented Windows Explorer com-object was popular).

    lesha

    I work on Windows and Mac, and if I'm setting up a server, it's Linux. I cleanly reinstalled OS X a couple of times, but everything is simple there - I chose the date in TimeMachine 10-15 minutes and the system is ready.
    On Windows, I have most of the programs portable, I put only chrome because otherwise the Adobe software package is not updated, because from the CC version they are downloaded through the Cretive Cloud. I don't see the point of building a garden with automation. PowerShell may be good, but I have nothing to automate on Windows, and for Linux and OS X there is bash, which I have been using for a long time.
    If a friend asks to "reinstall Windu for me, otherwise something is buggy" I put the system from an external drive in my own "proprietary" way, and let the rest be set to myself

  • By setting new version operating system Windows, novice users come across new names of programs that they may not have heard before and the purpose of which they do not understand. One such application is PowerShell. If it is preinstalled in the OS, then it serves for something. What is this Winodws PowerShell program, users often ask this question. Let's take a closer look at it.

    Working window PowerShell

    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 is capable of providing more flexibility in configuring and managing your computer in operating system Windows. In other words, the same command line with additional features.

    PowerShell Features and Purpose

    You can see that this Winodws PowerShell program is the interface to the scripting language and is also the platform for executing those scripts. PowerShell was released in 2006, which was included in the second service pack and since then the program has become part of all Microsoft operating systems. The scripts of this program have the PS1 extension and are able to run like the BAT and CMD files.

    This scripting language was developed primarily for Microsoft business clients who require powerful tools to automate various tasks in the management of computers and servers, under Windows control... The language is based on the .NET platform from Microsoft.

    Windows PowerShell provides the ability to automate many different tasks and processes. It allows you to establish control over services, accounts, settings, processes, etc. The scripting language accepts all commands from the OS command line, in turn has a rich language of its own, which consists of certain commands, they are called cmdlets. These cmdlets work on the Verb + Noun principle. For example, "Get-Help", which in English means "Get Help". This cmdlet brings up Help. To get information about a cmdlet, enter "Get-Help Get-Process". In this case, the program will provide information about the "Get-Process" comendlet.

    Launching and Running Windows PowerShell

    There are a few different ways run the Windows PowerShell program on the OS. For ease of searching for programs in the operating system, there is a search box. You can find it by opening the My Computer shortcut at the top of the screen on the right side. Enter PowerShell and open the program in the search results. In Windows 10, the program can be launched from any working folder, for this you need to click on the "File" button in the upper left part.


    Starting PowerShell

    To demonstrate how this works Windows program PowerShell, let's try some of its features, for example, let's clean the trash can. There is a special cmdlet for this function - "Clear-RecycleBin". It is useful for writing a script when servicing computers. When entering such a command, you need to specify the local drive where the application is located with which you want to perform this action: "Clear-RecycleBin C:". Next, a line with a confirmation request will appear, here you must press the "Y" and "Enter" keys.


    Emptying the Trash with PowerShell

    If you add the "-Force" part to the "Clear-RecycleBin C:" cmdlet, the trash can be emptied without confirmation.

    1. Let's unpack the archive using PowerShell.
    2. For this, there are predefined commands "Expand-Archive" and "Compress-Archive".
    3. To archive the folder "C: \ file \" to "C: \ archive \ file2.zip", follow the specified command: "Compress-Archive –LiteralPath C: \ file \ -DestinationPath C: \ archive \ file2.zip ...
    4. As a result of executing this command, an archive with the name “file2.zip” will appear in the above directory, in which the contents of the folder “C: \ file \” will be archived.

    Basic PowerShell Cmdlets

    This program has a lot of different commands that are applied to various Windows components and it will not be possible to describe all of them in this article. Some basic Windows PowerShell commands are:

    1. "Update-Help" - update help for a specific component.
    2. "Get-Help" - getting help.
    3. Get-Command - Search from a list of cmdlets.
    4. Format-Table - An overview of the result of a specific command in a table.
    5. "New-Variable" is a new variable.
    6. "Remove-Variable" - deleting the value of a variable.
    7. "Set-Variable" - specify a value for a variable.
    8. "Format-Wide" - an overview of the result of the executed command in the form of a table, in which there is only one property for one object.

    For many users, this integral element of the Windows operating system seems to be a real mystery. Opening it, they see a list of incomprehensible symbols, which is not possible for the uninitiated to understand. But do not underestimate it, this is a program that carries an important management function, capable of simplifying work with a PC, no matter how it is expressed.

    Utility fully automated, minimal human intervention is required to manage workflows. All you need to do is give the correct commands. But before doing this, you need to understand the main question: What is Windows PowerShell, for what purposes it serves and what functions it performs.

    Program overview

    In fact, this is an improved version of MS-DOS - the oldest disk operating system from Microsoft, released back in the mid-80s. last century. It contained applications, with function of interpreters far from perfect, who knew how to set a few simple commands.

    Developers have repeatedly tried to compensate for the shortcomings of MS-DOS with additional scripting components such as MS Script Host with languages ​​such as Jscript, but this only partially solved the problem. In 2003, development began on a program capable of replacing the old shell called Monad, now known as PowerShell. Although his first launched at the end of 2006 and included in Windows XP, in its final form it was released only after 10 years of continuous improvements, in 2016 when it received open source. PowerShell is widely used in Windows 7, 8, and 10.

    Windows PowerShell - what is it

    It will not be possible to answer this question in a nutshell, it is too complicated and requires detailed consideration. It is an extensible open source automation tool — a wrapper that encloses a scripting CLI for executing the scripts it contains. The set of scripts enclosed in system files has the PS1 extension, but for the convenience of users runs as usual BAT and CMD files.

    Thus, PowerShell is nothing more than a scripting language built on the .NET platform to perform tasks related to managing files stored on the system disk, running processes and services. In addition, he is subject to account management on the Internet and any settings, from system settings, to settings for the functionality of individual applications. But PowerShell itself is only a shell, the main functions are performed by the accompanying elements that fill it. Next, we will try to understand PowerShell so that even “dummies” can understand how to work with the utility.

    Cmdlets

    The most important are cmdlets, executables that contain own program loaded into a computer to complete the assigned tasks. They are the main component of the Windows Power Shell, responsible for its functionality, and are a set of commands for running a script entered at the command line.

    This is slightly different from the queries entered in the browser search bar, but has the same principles... The shell contains a stored collection of hundreds of such commands that perform specific tasks. The cmdlets are formed according to the usual Verb + Noun principle, which reflects their purpose.

    Conveyor

    The second most important element (command type) in PowerShell, which passes the output of some cmdlets to the input of others, acts as an intermediary between them. The conveyor is mainly used for transfer and return not only cmdlets, but also any other objects. He is also capable of performing more complex and responsible tasks. Most importantly, this does not require writing complex algorithms and scripts.

    When creating the pipeline, Microsoft developers used the analogue used in Linux as an illustrative example, but did not copy it, but made it as much as possible convenient and functional... If we compare them, the only common feature between them is the characteristic of functions, expressed in a virtually continuous stream of data containing millions of characters.

    Scripts

    Scripts are less significant types of commands in PowerShell, which are blocks of codes that are stored in a separate file from the rest, but also support the PS1 extension. Their main advantage serves the fact that the stored codes do not need to be dialed manually each time. It does not matter in which of the text editors they are written, even in Word, even in Paint, the principle is only to adhere to the installed extension.

    The shell itself has an integrated scripting environment that can be used even more. simplify their writing... To create them, the text formatting rules have been established, the "$" symbol is used in front of the name, the path to the saved file is enclosed in curly braces, and the properties are accessed using "." ahead. Scripts complemented by arguments using parentheses and comments with "#" symbols.

    Supplements

    In addition to the standard command types and 240 cmdlets contained in PowerShell, it includes many additions designed to further simplify your work and expand functionality. List of the most important additions:

    How to start PowerShell

    An additional convenience of the program is that it is launched by PowerShell using different ways that differ technically, but are identical for all versions of Windows, including Windows 10. Thanks to this, everyone selects an individual approach, depending on the situation. There are several ways to start.

    Using "Search"

    To do this, you need to click on the corresponding icon located on taskbar, or use the key combination " Win +S". In the window that opens, in the search box, type "powershell", and in the output, select "Classic sentence". You can also call context menu right click, where to use "Run as administrator".

    Through the start menu

    Click on the "Start" button to open the list of applications, in the sorted group entitled "W" select the folder with the program. Expand it and click on the application in the top line. Here, also as an option, you can call the context menu with the right mouse button and run "as administrator".

    Using a keyboard shortcut

    This method presupposes a preliminary step of replacing the command line with Widows PowerShell with the Win + X Menu function. After that, enter the corresponding menu using a keyboard shortcut, or through the context menu by right-clicking on the "Start" button, where you can select the desired item in the presented list.

    Through the "Run" dialog

    One of the simplest ways, by opening the " Execute". To call it, use the key combination "Win + R", in the "Open" line, enter a command with the name of the program. To start it, press the "Enter" key or the "OK" button on the window panel.

    Using the "Task Manager"

    To open the manager, use the keyboard shortcut " Ctrl +Shift +Esc", In the window that opens, in the" File "tab, select the option" Launching a new task". In a new window, opposite the line "Open", enter "powershell" and press "Enter". If you need to create a task on behalf of the administrator, tick the corresponding option and confirm by pressing by clicking the "Ok" button.

    Through "Explorer"

    After opening it, you will need to specify the name of the folder or drive where the program will run. On File tab select the option "Run Widows PowerShell" and click on the desired item.

    Through the system folder

    In the search bar enter address programs: "C: \ Windows \ System32 \ WindowsPowerShell \ v1.0". In the list that opens, select the "powershell.exe" folder and open it with a double left click. To simplify the process in the future, you can create shortcut file and pin it to any convenient place: on the taskbar, in the "Start" menu, or on the desktop. If necessary, the shell will be launched by double clicking on the icon.

    Procedure for using the utility

    Upon first acquaintance with PowerShell, it seems incomprehensible, like formulas in higher mathematics, but this is a deceiving impression. In fact, it is quite easy to use the program if you understand its basics: how it works, the peculiarities of entering and executing commands. In that, different types slightly different, but the principles and rules remain the same for everyone.

    On simple example, the command specified as "Get-Help" is a kind of utility reference that provides general information as you type. If you need help on a specific process, for example, about mapped drives, you need to set the command - "Get-Help Get-PSDrive", and so on for any question, changing only the name of the cmdlet. For any action, for example, cleaning the basket from file garbage, "Clear-RecycleBin" is usually used, which is used for more important tasks in PC maintenance and for writing scripts. But he is also responsible for such a simple process as emptying the system recycle bins. First, you need to specify the disk to be cleaned, according to the principle: "Clear-RecycleBin C:" to confirm the action, enter the character "Y" and press "Enter".

    Working with a conveyor

    In operation, the pipeline is extremely simple and convenient, which makes it especially stand out against the background of other types of commands. For example, if output the result Get-Process containing information about active processes on the PC into the Soft-Object cmdlet, it will sort them by descriptors. Having translated the obtained values ​​into Where-Object, filtration will occur these processes for a given parameter, for example, the smallest amount of page memory. And if this result is output to Select-Object, it will select only the first 10 processes, taking into account the number of descriptors.

    Or one more simple example used to get information about the heaviest files stored on the system disk: The Get-ChildItem command opens a directory to select an object, Sort-Object will sort the selected object, and Select-Object will indicate its desired properties.

    Working with a script

    When creating algorithms, Windows PowerShell ISE is often used, a specially created mechanism, including for using scripts. In it, under the name "Untitled 1.ps1" is introduced body of code... Let's look at a simple example: "WMID WebMoney" in the name, conditionally set "wmid", save the file in the root of the C drive. 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 are also run from the OS command line, but this requires change path to it: "powershell.exe C: \ wmid.ps1". It is important to remember that scripts are not allowed to execute by default; to obtain permission for such actions, you must specify the Set-ExecutionPolicy command.

    Most Useful PowerShell Cmdlets

    The shell contains an impressive catalog of them, represented by hundreds of commands. It is not possible to remember all these names and the properties attached to them. But this does not need to be done, most of them are used extremely rarely, or even not at all applicable in practice. You should pay attention only to the most important, practical, carrying useful functions.

    Most helpful in application:

    • Get-Help - A reference for cmdlet assignment and general shell properties;
    • Update-Help - download and install updated help data;
    • Get-Command - search engine for the required commands, with auto-filling of the line;
    • Get-Alias ​​- reflects the set aliases, a general list or with specifics;
    • Get-PSDrive - Introduces running disks and the processes taking place on them;
    • Install-WindowsFeature - Role-based and component-based installer;
    • Uninstall-WindowsFeature - role-based and component-based uninstaller;
    • Get-History - Responsible for returning command lists executed at login.
    • $ hversion - Returns the version of the utility

    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 - uninstaller of cmdlets and their components.

    Formatting:

    • Format-List - extended reference;
    • Format-Table - displays a table of results of individual commands;
    • Format-Wide is an expanded results table with properties for individual objects.

    Internet:

    • Enable-NetAdapter - to enable the adapter;
    • Rename-NetAdapter - sets a new name and view;
    • Restart-NetAdapter - used to restart;
    • Get-NetIPAddress - Provides proxy server configuration data;
    • Set-NetIPAddress - sets a new configuration for the proxy server;
    • New-NetIPAddress - deals with the creation and configuration of a proxy server;
    • Remove-NetIPAddress - proxy server uninstaller;
    • New-NetRoute - used to add 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 - takes items along a given path;
    • Move-Item - to move items to other folders;
    • New-Item - used to create and design;
    • Remove-Item - uninstaller of checked items;
    • Get-Location - Shows the current location.

    Background jobs:

    • Start-Job - Performs startup;
    • Stop-Job - stops work;
    • Get-Job - opens the list;
    • Receive-Job - provides information about the results;
    • Remove-Job is an uninstaller for background tasks.

    Objects:

    • Measure-Object - used to calculate numerical aggregation parameters;
    • Select-Object - for selection with 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 the selected;
    • Get-Service - Provides data about active services;
    • Restart-Service - performs a restart;
    • Start-Service - used to connect the selected;
    • 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 starting the restored system;
    • Remove-Computer - uninstalls the local PC from the domain name;
    • Clear-EventLog - Clears the list of log entries.

    Content:


    What is PowerShell ISE

    It is a graphical shell for a scripting language that comes with the utility as an application, mainly for launching independent consoles. During startup, it is supported by Unicode and symbolic standards, with access to the main program interface tabs. It is developed to create scripts, edit and manage them, with the function of tracking their location. In addition, he knows how to work with text documents in any format and XML files, execute selected fragments of scripts, and due to the built-in editor, it is able to update the interface, expanding and supplementing it.

    Convenience of work is created by color syntax highlighting, which greatly facilitates testing for identifying errors and inconsistencies in codes. With the help of the environment, it can copy and change significant fragments in codes, run individual parts of scripts. It is noted that ISE is far superior to the Power Shell consoles itself, and is quite capable of replacing it.

    Removing a program

    Microsoft PowerShell is a system component, so you can't uninstall it in principle. Of course, if you really want to, you can use and remove this system component, but this can lead to the inoperability of the system, therefore Not recommended do it.

    It is worth noting, though, that sometimes it is necessary to uninstall Windows PowerShell 1.0 because the operating system may not be updated due to this element. You can do it like this:

    • Launch system search and enter appwiz.cpl.
    • In the window choose- View installed updates.
    • Are looking for required component in the list of updates, usually KB928439 and remove it.

    Windows PowerShell, even at a 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 created not at all 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 that is required is to delve into the intricacies.

    We all know what the command line is, what opportunities it provides, but not everyone knows about a similar interface called. In fact, it is almost the same command line, only with much more extensive capabilities. This article will discuss what PowerShell is and what this tool has to offer us.

    Definition of PowerShell

    Let's start with what a shell is. A shell is an interface that allows you to take advantage of some of the functions of the operating system. Thus, PowerShell is a shell developed by Microsoft for more automated task execution. This tool is built on top of .NET and a command line shell and scripting language.

    Also, there is such a thing as, which acts as an integrated scripting environment, in other words, it is a graphical interface with which we can create some kind of scripts, and we do not need to enter all the commands on the command line for this.

    The first version of the PowerShell tool appeared back in 2006 for Windows XP, Server 2003 and Vista. On this moment the latest version of the tool is 4.0. Released in 2013 along with Windows 8.1.

    What does PowerShell do?

    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 which ones are connected to the computer, and so, this can be done using PowerShell. You can also create, which will be executed in background while you go about your business. If superfluous background processes that load systems, they can be disabled using PowerShell. Also, you can create a document that will store information about computer networks or something else.

    Thus, using this utility, you can easily and quickly perform time-consuming tasks, as well as create any scripts or combine several commands.

    In the event that you are a network administrator, then PowerShell can help you with work, for example, with Active Directory. Also, it is worth noting that the utility contains over 100 commands. This suggests that it will help you solve most of the problems.

    Running PowerShell on Windows 7

    In order to run PowerShell on this operating system, you need to enter "" in the Start search box.

    In another way, the tool can be opened by going to the Start menu, all programs, standard and the folder Windows PowerShell.

    Running PowerShell on Windows 8.1

    To open PowerShell in Windows 8.1, you must enter in the search keyword"" To open the search, click Win + Q.

    Another way to open is through the window " Execute". Push Win + R, the window you type in opens.

    Daily use

    This tool is used by many IT specialists and administrators, and for good reason, as it provides great opportunities and reduces the time for performing any tasks.

    If a user has a large network in his use, which consists of several hundred servers, then it will be necessary to implement a security system that will work when using a certain service. The problem is that you need to check if this service is installed on all servers. Of course, you can manually connect to each server, but the management will not like it very much, since it will take a very long time to complete such a task.

    To reduce the work time to several minutes, you can use PowerShell, with the help of which, using one script, we will collect all the necessary information and save it into a separate document.

    Also, quite a few books have been written about this tool, nevertheless, this tool provides ample opportunities that are unlikely to be fully described in this article. Thus, if you are interested in this topic, you can start studying it in more detail.