Disable PSReadLine Command Logging

Copper Contributor

I need to disable PSReadline history save for all users in my organisation to prevent commands being written out to

%UserProfile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_History.txt

 

Set-PSReadlineOption -HistorySaveStyle SaveNothing only works for the current user context and in fact only seems to be applied for the current session and does not persist.

 

Are there GPO templates or registry keys that can be used to suppress the output?

Has anyone done this already?

 

 

1 Reply

@GrahamP67 

 

I understand that you need to disable PSReadline history save for all users in your organization to prevent commands from being written out to %UserProfile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_History.txt.

The Set-PSReadlineOption -HistorySaveStyle SaveNothing command only works for the current user context and only seems to be applied for the current session, not persisting.

You may be able to use Group Policy to achieve this. Here is an article that outlines how to do this: https://devblogs.microsoft.com/scripting/using-group-policy-to-manage-powershells-psreadline-module/

Alternatively, you could create a PowerShell script that runs on startup and sets the PSReadlineOption for all users. Here is an example:

Create a PowerShell script with the following code:

$users = Get-ChildItem -Path "C:\Users" -Directory | Select-Object -ExpandProperty Name

foreach ($user in $users) {
$path = "C:\Users\$user\AppData\Roaming\Microsoft\Windows\PowerShell\Microsoft.PowerShell_profile.ps1"
if (!(Test-Path -Path $path)) {
New-Item -ItemType File -Path $path -Force
}
Add-Content -Path $path -Value "Set-PSReadlineOption -HistorySaveStyle SaveNothing"
}


Save the script as a .ps1 file, for example: DisablePSReadlineHistorySave.ps1.


Deploy the script to all computers in your organization, for example, by using Group Policy or another distribution method.

When each user logs on, the script will add a line to their PowerShell profile that sets PSReadlineOption to disable history save.