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
10,634
81
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
10,634
81
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 }
 
May 20, 2008
10,634
81
Syracuse, NY, USA
This is a task that I was running in Powershell using the above technique.

I just wanted to run it via PSHELL, which I can now do, thanks to your solution.

I was hoping that, since PSHELL and TCC share environment variables, that the history would also be shared.

Joe
PSHELL doesn't start PowerShell.exe. The only environment variables involved are TCC's.
 
Thread starter Similar threads Forum Replies Date
Joe Caverly PowerShell 3
Joe Caverly PowerShell 1
Joe Caverly PowerShell 1