Windows 7 Powershell: A guide
How to solve complex tasks with the new PowerShell in Windows 7. Our tutorial shows examples and gives detailed instructions.
Understand the new concept of powershell
In contrast to the old command prompt, the Powershell works consistently object-oriented; it is based on the objects of the Microsoft .NET framework. Another advantage in addition to the expanded range of functions: Access to objects is uniform. Instead of the previous DOS commands, so-called cmdlets (read "commandlets"), which you can use the pipe character "|" can chain within a line. This means that one cmdlet processes the output of the previous one and thus enables compact formulation of complex tasks. How to start the Powershell:
- To call up the Powershell, navigate in the start menu to "All Programs"> "Accessories"> "Windows PowerShell" or type "powershell" in the search line.
- The result window shows three objects: "powershell" starts the direct command environment, "Windows PowerShell ISE" a simple graphical user interface, which helps above all with the development of scripts. As a third element, modules are still available. Use the clear graphic variant to get started.
- For repeated use, it is advisable to set up quick access to the PowerShell. To do this, either create a shortcut or right-click on the program and then select the context command "Pin this program to the taskbar".
New command syntax
- The Powershell ISE window is divided into a script, output and command area. You activate the areas with a click of the mouse or via the "Show" menu. Using the "File" dialog, you can save, load and execute scripts step by step in the "Debug" menu.
- Start at the command line in the command area. The prompt of the Powershell shows the current path as usual. The names of the commands predefined as cmdlets follow the structure of the verb noun. For example, the cmdlet "Set-Location" with the path serves as an argument for changing to another directory. "Get-Childitem" shows the contents of a folder. You can get an overview of the existing commands with "Get-Command".
- Some familiar DOS commands can still be used - "cd" (change directrory) also works for changing the directory. At least you can still call it up, because Microsoft has redefined all commands under the hood. This is ensured by the assignment of alias terms that call the corresponding cmdlet when you enter the abbreviation. A list of the defined alias terms is provided by entering "Get Alias". When using the old commands, however, you must note that familiar parameters usually no longer work, since a changed syntax has been defined for the cmdlets. You can find the correct spelling and all possible parameters in the help for the respective cmdlet, for example with "Get-Help Get-Childitem". Use the command for which you need help as an argument. The example shown provides help for "GetChilditem", the cmdlet for the good old directory command "dir"
- Note: You can access help at any time in the graphical user interface with the [F1] key, either generally or context-sensitive to the current input.
Link Powershell commands
A simple example of listing folder contents shows how the concept of cmdlets extends the functionality known from the old DOS command "dir" in just a few steps. A typical task is to find objects among the files contained in a folder that fulfill certain properties. For example, find the five largest MP3 files in one directory. In the Powershell, you can do this quickly with a few chained commands. To do this, type the following:
- Get-Childitem -recurse -include * .Mp3
- Sort-Object length -descending
- Select-Object -first 5
This command first recursively determines the MP3 files contained in all subfolders and passes them on as an object. The second step sorts the list in descending order by size, while the third step finally selects the first five elements from it