How to save command output to file from Command Prompt and PowerShell on Windows 10

The commands that you execute in PowerShell and Command Prompt can output information. Sometimes, it’s just a few lines e.g., when you check the ping, or it might be a lot of lines e.g. when your local IP address or your external IP. Regardless of how long the output is, sometimes you just need to save it to a file so that you don’t have to fetch the information again and again. Both Command Prompt and PowerShell support copy and paste but you can also save command output to a file when the command is run. Here’s how you can do that in both Command Prompt and PowerShell.

Command output to file – Command Prompt

Open Command Prompt and enter the command that you want to run. Before you tap Enter though, add the following at the end;

> name-of-file.txt

You don’t have to create the text file first. Command Prompt will do that for you. If you enter just the name of the file, it will be created in the same directory that the Command Prompt is currently in. You can save the output to a different location by adding the path to the folder you want to save the output to.

> path-to-folder\name-of-file.txt

If you want to save the output to a file but also view it in Command Prompt, you can do that with this command;

> path-to-folder\name-of-file.txt | type

Command output to file – PowerShell

In PowerShell, you can send command output to a file the same way you can in Command Prompt. Enter the command you want to run and before you tap Enter, add the following at the end. Again, you won’t have to create the text file. PowerShell will do that for you.

> name-of-file.txt

This will save the output file to same directory that PowerShell is currently in. To save the output to a file in a different location, you can specify the path to the folder where you want to save it.

If you want to view the output, you can’t do that at the same time that the file is being created. Once it has been created, run this command and you will be able to view its contents.

Get-Content -Path "path-to-file\file-name.txt"

If you’re wondering whether the output can be saved to a different type of file, the answer is no. Both Command Prompt and PowerShell can only natively write to/create text files and there’s no way to format the output so that when it’s saved to a file, it looks a certain way.

Read How to save command output to file from Command Prompt and PowerShell on Windows 10 by Fatima Wahab on AddictiveTips – Tech tips to make you smarter

How to check the checksum of a file on Windows 10

Downloading a file used to be a risk. It can still be risky and you might still end up with malware on your system but there are more robust protections in place now. Both your browser and your OS scan items to make sure they’re safe to run. Another way to make sure you’ve downloaded a safe file is to check the checksum of a file.

Checksum values

No two people can have the same fingerprints. Similarly, no two files can ever have the same checksum values. If a file has been modified, its checksum value will be different from what it was before the modification was made.

When you check the checksum value of a file, you first need to know what its original value was. Normally, developers who are distributing software will provide it themselves on the download page for their product. Checksum is applied using MD5 or SHA. Some developers will generate Checksum values from both so that you can check whichever you want.

Check checksum value

Microsoft provides a tool called File Checksum Integrity Verifier utility that you can use to check the checksum value of a file.

Download and extract it. You will have to use it from the Command Prompt. Open Command Prompt and use the cd command to move to the folder you extracted the tool to.

Move the file that you want to check the checksum value for to the same directory as the one you extracted the File Checksum Integrity Verifier utility to and then run the following command to run the check.

Syntax

fciv.exe -both filename

Example

fciv.exe -both ReIcon_x64.exe

This will display both the MD5 and SHA checksum values. You can manually compare them, use a spreadsheet tool, or a simple difference checking tool.

Checksum does not match

In the event that the file you downloaded and ran the check for generates a different checksum than the one the developer provided, you might be dealing with a malicious or corrupt file.

If the file is corrupt, it’s likely because it didn’t download correctly. Try downloading it again. If the problem persists, it is entirely possible that the file that is available has been modified in which case, you should not use/run it. A mismatch in checksum value may also indicate a file that has been modified. This tends to happen with free or open-source apps that people try to re-distribute. They add in additional code that is meant to harm your system and bundle it into a trusted app.

The only way to stay safe is to always download apps from their official sources.

Read How to check the checksum of a file on Windows 10 by Fatima Wahab on AddictiveTips – Tech tips to make you smarter

How to find compressed files and folders on Windows 10

Files and folders can be compressed to save space on your disk. This compression isn’t the same as zipping a file or using a utility like WinRAR to compress them. Instead, it’s a built-in feature on Windows 10 that you can apply to entire drives, select folders, and specific files. These compressed items are indicated with two blue arrows on the file/folder icon. They can be identified visually however you can also use the Command Prompt to find compressed files and folders on Windows 10.

Compressed files and folders

You can scan entire folders for compressed files and folders. When you scan a folder, it will list the compressed items at its root and not nested items. If the folder you’re scanning has a compressed folder which in turn has other compressed items nested under it, this scan will only list the parent folder that’s compressed. You can use a modifier to find the nested compressed items as well.

Open Command Prompt and use the cd command to move to the folder that you’d like to scan for compressed files and folders.

Syntax

cd "path to folder"

Example

cd "C:\Users\fatiw\Desktop"

Once you’re in the folder, run the following command to get all the compressed items at the root of that folder;

compact

Look through the list of files and folders that Command Prompt outputs and all the items with a C before their name are compressed items.

To view nested compressed items as well as those at the root of the current folder, run the following command;

compant /s

The list of files you get is probably going to be a long one. Command Prompt does let you copy and paste from it so you can paste the output into a text file, or just use > followed by the name of a text file to save the output to.

Compressing files and folders

You can compress files and folders from the Windows GUI but the compact command can also compress them if you run it with the /c modifier. This will compress everything in whichever folder you point it to.

Uncompressing files and folders

You can remove compression from the Windows GUI however, since you’re already using the Command Prompt, you can use the /u modifier with the compact command to remove compression from the current folder. This will remove compression from all items at the root of the folder.

If compressing files and folders seems a bit confusing with compact, it’s best to just go with the GUI options that Windows has. They work just as well.

Read How to find compressed files and folders on Windows 10 by Fatima Wahab on AddictiveTips – Tech tips to make you smarter

How to view folder ownership on Windows 10

The admin account on Windows 10 gives you access to most areas on the operating system however, it doesn’t give you unrestricted access. You will find that there are still some folders that you cannot access, and some modifications to the Windows registry that you cannot make. When you try to make these modifications, Windows 10 gives you the access denied alert and authenticating with the admin user does not grant you access. If you need to view folder ownership on Windows 10, there’s a fairly easy way to do it.

View folder ownership

In order to view folder ownership, you need to download a free tool from Microsoft called PSTools. You can download it here. It will download as a zipped file, Extract it, and then copy the folder’s location.

Open Command Prompt with admin rights, and use the cd command to move to the extracted folder. This is where the folder’s location that you copied to your clipboard will come in handy.

Example

cd C:\Users\fatiw\Desktop\PSTools

Once you’re in the folder, run the command below.

psexec -i -s cmd.exe

You will see an on-screen alert telling you to accept the PSTools EULA. Go ahead and accept it, and a new Command Prompt window will open. Close the Command Prompt window that you executed the first two commands in. This new window is where you need to enter the command that will reveal folder ownership.

In the new Command Prompt window, run the following command;

icacls "Path to folder"

Example

icacls C:\Windows\System32

The results will return who owns the folder. The screenshot below shows that the System32 folder is owned by TrustedInstaller. Not all folders under the System32 folder are restricted to the admin user. For example, you can access the AdvancedInstallers folder easily. This means that some folders inherit the permissions of the parent folder, while some do not.

To narrow down which permissions a particular folder has, simple run the same icacls command again but include the full path to the folder that you want to access;

Example

icacls C:\Windows\System32\DriverState

Understanding permissions

The permissions, when displayed, are abbreviated and even if they weren’t the average user may not be able to understand them. Microsoft has a helpful document that will explain the various terms that the icacls command returns when it shows you folder ownershhip. Scroll down to the Remarks section to get started.

Changing ownership

As an admin user, you can change ownership of a folder from the Windows 10 GUI, or by using third-party apps. Regardless of how you choose to do it, make sure you know what you’re doing when you modify one of these restricted folders as changing something here could have a negative impact on your system.

Read How to view folder ownership on Windows 10 by Fatima Wahab on AddictiveTips – Tech tips to make you smarter

How to set Account lockout threshold on Windows 10 for local accounts

Passwords have become necessary to lock devices whether they’re desktops or smartphones. Passwords for devices can be guessed especially if someone is able to watch you enter a password or knows you well enough to make a few guesses and get it right. To safe guard against this, you can lock Windows 10 after the failed login attempts exceed a certain number by setting the account lockout threshold. This security measure is, unfortunately, only available if you use a local account on Windows 10.

Account lockout threshold

Locking Windows 10 after failed loginĀ  attempts requires setting the Account lockout threshold which can be set from both the Group Policy, and from Command Prompt. Since Group Policy is not available on Windows 10 Home, we’re going to show you how you can set the Account lockout threshold from Command Prompt so that you have one process that works everywhere.

You will need admin rights to set the Account lockout threshold.

Open Command Prompt with admin rights and run the following command. It will show if the Account lockout threshold is set to anything. If it has never been set/configured before, it will say ‘Never’ against its entry.

net accounts

To set the threshold, run this command and replace the number at the end with the number of failed attempts that should trigger the lock out. The command below will set it to ten login attempts.

net accounts /lockoutwindow:10

The command will return the same ‘Never’ value for the threshold entry however, if you run the net accounts command again, it will show the correct threshold that you’ve just set.

That’s all you need to do. Any time you want to reset this to 0, run the same command but replace the number at the end with 0.

Since this does not work with Microsoft Accounts, you should know that there are other ways to keep your system safe. For one, try using a PIN by default and use one that is alphanumeric instead of just four numbers. If someone fails to guess the PIN one too many times, Windows 10 will suggest they use an alternative sign in method. Additionally, learn how you can remotely lock your Windows 10 PC should the need arise. It’s also a good idea to set up two-factor authentication for a Microsoft account so that, in case someone uses it to sign in and change your account settings on Microsoft’s website, they are prevented from signing in.

Read How to set Account lockout threshold on Windows 10 for local accounts by Fatima Wahab on AddictiveTips – Tech tips to make you smarter