How to use PowerShell History on Multiple Devices

Windows PowerShell is a powerful tool to automate tasks and perform general maintenance routines on a computer. It is especially useful for power users as it allows them to be productive and…

Using same PowerShell history on multiple devices

Windows PowerShell is a powerful tool to automate tasks and perform general maintenance routines on a computer. It is especially useful for power users as it allows them to be productive and perform tasks faster than by only using the graphical interface.

Having said that, the commands used in PowerShell can be tricky, lengthy, and quite confusing for some. The cmdlets in PowerShell are endless. Some are for beginners while others are for advanced-level users. Remembering them all is impossible.

Even if you do remember some of them, it can be infuriating to type the same, lengthy commands on multiple computers when managing a few altogether.

The article describes how you can shorten the process of typing the same commands time and time again by using the same commands you have entered on one computer on an endless number of other computers.

How PowerShell stores cmdlets history

As you may already be aware, Windows PowerShell stores the commands that you have used which can be brought up by using the up and down arrow keys on the keyboard. For example, if you have entered a command earlier in time and since ran a few other commands as well, you can bring up the initial command that you entered simply by pressing the Up button several times and scrolling through the commands. Once you have run the command, press the Enter key.

All the cmdlets and text entered in PowerShell are stored in a text file named ConsoleHost_history.txt at the following location:


You may paste the path given above to have a look using File Explorer.


Opening the text file will reveal all the commands that you have used since the file was created. This is how PowerShell brings up the history of commands within the console.

console history text

How to use PowerShell history on multiple devices

Let’s talk about how to‌ ‌use‌ ‌the‌ ‌same‌ ‌PowerShell‌ ‌history‌ ‌on‌ ‌ multiple‌ ‌devices. This technique is especially useful for sysadmins who frequently need to perform the same tasks on each computer separately using PowerShell.

History files are stored on Microsoft OneDrive, which provides 5GB of free storage per user (you can also use this method to get 5TB OneDrive storage for free). We change each device’s history saving location ‌to‌ ‌a‌ ‌text‌ ‌file‌ ‌on‌ ‌OneDrive. In this manner, the file is updated across all computers, allowing you to recall commands from one machine to‌ ‌another.

Go through the steps below to use PowerShell history on 2 devices and then the same logic can be applied on any number of devices.

Note: In order to keep the text files on OneDrive in sync, ensure that each device has an active internet connection.

Set up OneDrive on your computer

To begin the process, you will first need to ensure that you have the same OneDrive account set up across all the devices on which you plan to share your PowerShell history. Follow the steps below to set up OneDrive on Windows 10. If you have already set up OneDrive on your computer(s), you can skip this step and proceed to the next one:

  1. Click on the OneDrive icon in the System Tray to expand it.
    not signed in onedrive
  2. Now click Sign In.
    sign in
  3. In the Set up OneDrive window, enter your Microsoft account email address and click Sign in.
    sign in 2

You have now successfully set up OneDrive on your computer. This process needs to be repeated across all devices you plan on sharing your PowerShell history with.

Reroute PowerShell history file

Now we need to change the location of the text file where PowerShell history is saved, and move it to OneDrive that we have just set up.

To change the location of the history text file, launch PowerShell with administrative privileges, and then use the following command:

Set-PSReadLineOption -HistorySavePath PathToOneDrive\NameOfFile.txt

Replace PathToOneDrive with the path to the OneDrive folder and NameOfFile with the name of the text file you wish to save it by.

Note that the name needs to be the same across all devices as the same command needs to be repeated on all devices you wish to use the history cmdlets with. Here is an example of the command:

PS command

Since the default path of the OneDrive folder is usually within the user account folder, remember to be careful with the command in each device as the usernames may vary.

Once both the processes (OneDrive setup and rerouting PowerShell history file) are completed, you can recall the commands entered on one PC on another simply by using the up and down arrow keys.

Closing words

Perhaps this may seem like a redundant step, but having to enter a command on every single computer manually is even more troublesome. This can be avoided if all PowerShell consoles on all devices obtain their history data from a single location – the history-saving text file.

Latest posts
Powershell Generic
Microsoft Releases PowerShell 7.4.0 LTS, Updates PowerShell 7.3.10 And 7.2.17 (Offline Installers)

Download the latest .NET 8-based PowerShell 7.4 here.

View post
Powershell Generic
Download PowerShell 7.3.9 & 7.2.16 LTS (Offline Installers)

Download PowerShell 7.3.9 and 7.2.16 LTS for Windows, macOS, and Linux using the provided offline installers.

View post
How To Zip And Unzip Files With PowerShell On Windows
How To Zip And Unzip Files With PowerShell On Windows

Manage your data better with controllable compression ratios to create zip files with PowerShell.

View post

Leave the first comment