Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

GET-History with PSHELL

Aug
1,954
71
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
 
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
 
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 }
 
Hey @vefatica , the Import-CSV does what I want.

After Importing the CSV file, I can run;
Code:
pshell /s "2..3 | ForEach {Invoke-History -Id $_ }"
to run commands 2 through 3 from my history.csv file.

Joe
 
Hey @vefatica , the Import-CSV does what I want.

After Importing the CSV file, I can run;
Code:
pshell /s "2..3 | ForEach {Invoke-History -Id $_ }"
to run commands 2 through 3 from my history.csv file.

Joe
I guess that's good. How's the CSV file getting made?
 
Back
Top