System hacks: practical and simple PowerShell commands

Starting from Windows 10 version 1703, PowerShell has taken the place of the former Command Prompt and become a must-have tool for Windows administration. However, many ordinary Windows users do not know what it is used for. In fact, by executing simple commands in the PowerShell window, you can often solve some practical problems.

Preliminary Knowledge: Basic Use of PowerShell

In addition, PowerShell can be invoked in the File menu of Explorer (Figure 1); of course, you can also call Powershell directly through Cortana.

1823A-PS-1

Similar to the command prompt window, PowerShell also performs tasks in a command-based manner. In addition to typing commands one by one in the PowerShell window, we can also write commands to a plain text file with the extension .ps1 and then execute them by right-clicking the menu and selecting “Run with PowerShel “to execute it. By double-clicking on the .ps1 file, you can also directly launch the dedicated PowerShell script editor Windows PowerShell ISE and edit the PowerShell script file (Figure 2).

1823A-PS-2

1. Quickly grasp the number of Start menu items

The Windows 10 Start menu is all-encompassing, but it’s just different kinds of shortcuts. So, how do you know the number of shortcuts that this computer’s Start menu has? Simply execute the following command in a Powershell window (Figure 3).

Get-StartApps | measure

1823A-PS-3

After executing the command, we see that the number of Start menu shortcuts (170 in this case) is already displayed after the Count counter.

If you omit the subsequent measure parameter and just execute the simple Get-StartApps command, you can get information about each shortcut, including its name and ID information (Figure 4).

1823A-PS-4

Tip: The use of checking the number of Start menu shortcuts

Earlier version of Windows 10 system, when the number of shortcuts in the Start menu is too many (more than 512), the problem of Start menu failure may occur. To avoid this problem, you can count them in advance, and if they are about to exceed the limit, you can clean them up in advance to prevent the problem before it happens.

2. Create folders in bulk at once

Using PowerShell simple command, you can create a group of folders arranged by serial number. For example, to create “E:999” folder “experimental results 1”, “experimental results 2” … …all the way to “Experiment 20”, a total of 20 folders.

First, execute the “E:” command and “CD 999” in a PowerShell window to switch to the current working folder 999, and finally execute the following command (Figure 5).

MKDIR $(1..20 | %{“Experimental Results $_”})

1823A-PS-5

In this way, the above 20 folders are automatically created under folder 999.

Command parameters: MKDIR is the command to create folders; the number string 1…20 indicates the serial number of folders; “experiment result” is the prefix of folder name; $_ indicates the serial number, and the result is consistent with the number taken before.

3. Generate the original file information checksum

We often see that some software downloads on the Internet will provide SHA1, MD5 and other file checksums, such as the download of ISO installation files from the Microsoft website. How to generate these checksums? Actually, you can generate various file checksums with PowerShell.

For example, to generate MD5 checksum for the file “E:Win7_PE3.0_51M.iso”, you can execute the following command in the PowerShell window (Figure 6).

Get-FileHash E:Win7_PE3.0_51M.iso -Algorithm MD5| Format-List

1823A-PS-6

After the command is executed, the result displays the Hash checksum value of MD5 type. If the command line does not take the -Algorithm parameter, i.e., does not specify the type of Hash value to be verified, the default verification type is SHA256 value.

Tip: Get-FileHash command can verify the Hash value types include: MD5, SHA1, SHA256, SHA384, SHA512, MACTripleDES, RIPEMD160. to generate a certain check code, just replace the MD5 in the above command with the corresponding parameters.

Tip: Create a new PowerShell file with the right-click menu

PowerShell is powerful, if you want to automatically execute more than one command at a time, create a text file with .PS1 extension and add commands to it. For your convenience, you can add the command to create a new PowerShell script to the context menu. Simply create a new ShellNew sub-section in the Registry Editor under the “HKEY_CLASSES_ROOT.ps1” branch, and under that sub-section create a new string value named NullFile (the value data is left blank by default) (Figure 7).

1823A-PS-7

So right-click on the desktop or Explorer, select “New”, and you will see the “Windows PowerShell Script” item (Figure 8).

1823A-PS-8

Leave a Comment