GET-History with PSHELL

I am using;
Code:
  _x64: 1
_admin: 1

TCC  24.02.49 x64   Windows 10 [Version 10.0.18362.116]
Using Get-History via PSHELL /S does not return anything.

I have tried;
Code:
e:\utils>pshell /s "Get-History"
...and;
Code:
e:\utils>pshell /s "Get-History | out-file 'e:\utils\results.txt'"

e:\utils>type results.txt
...and;
Code:
e:\utils>pshell /s "$x = Get-History"

e:\utils>pshell /s "$x"
Is this WAD? I have no problem with the Get-History command working in Powershell.

Joe
 
May 20, 2008
9,445
63
Syracuse, NY, USA
Why it should? Normally, history is for typed commands. Not for API calls.
I think AnrDaemon is correct. Get-History would work if there were some history to get. Try this.

In a PowerShell session, run a few commands and then
Code:
Get-history | Export-Csv path\file
Quit PowerShell and in a TCC session
Code:
PSHELL /s "Import-Csv path\file | Add-History"
PSHELL /s Get-History
 
May 20, 2008
9,445
63
Syracuse, NY, USA
FWIW, these commands, in Microsoft.PowerShell_profile.ps1 (or whatever it's named) will give a history that persists between sessions. This history is loaded when you use PSHELL.

Code:
$HistoryFilePath = Join-Path ([Environment]::GetFolderPath('UserProfile')) .ps_history

Register-EngineEvent PowerShell.Exiting -Action { Get-History | Export-Clixml $HistoryFilePath } | out-null

if (Test-path $HistoryFilePath) { Import-Clixml $HistoryFilePath | Add-History }