|
Thanks for the ideas. I'm phone posting so forgive me. What I need is an "on the fly" ad-hoc way of saying "I want to log to a custom CSV the command/script I'm about to execute". I don't have a need to log other stuff I run. Maybe I can figure out a way to retroactively parse history for the info?
|
# ? Apr 15, 2024 17:53 |
|
|
# ? May 4, 2024 14:38 |
|
Are you capturing the output of that script, or just that you ran the script? If the script outputs something, just set a variable to be the called script like so (the script just does get-date) code:
code:
Happiness Commando fucked around with this message at 21:07 on Apr 15, 2024 |
# ? Apr 15, 2024 20:58 |
|
Thanks for the idea! I learned something new with that Start-Transcript. It's a weird short-term thing that isn't totally necessary, just something that can save me a bit of manual data entry. I'm mainly poking at it to see if I can automate it. At this point I'm thinking I can add a comment (e.g. ##LogThis!) at the end of each relevant command execution, then write a simple script that parses History and finds those comments, writing those commands to a CSV along with their execution time.
|
# ? Apr 15, 2024 23:54 |
|
I'm still not seeing what exactly you're trying to accomplish. Do you need to submit some kind of report of when you do a specific task? In that case, I'd honestly just auto-start a transcript as part of your profile.ps1, then grab the relevant data whenever you need to submit the report. Combine that with a Posh theme that auto-timestamps your prompt and you're probably golden. If you're trying to capture specific output from a command/script, adding | export-csv -NoClobber (or -Append) -NoTypeInformation -Path '$path\command-{$get-date}.csv' or similar code directly into your script is probably the right way to go. Wizard of the Deep fucked around with this message at 09:24 on Apr 16, 2024 |
# ? Apr 16, 2024 00:20 |
|
Hughmoris posted:Thanks for the idea! I learned something new with that Start-Transcript. Is this potentially related to fulfilling some security thing (e.g. ACSC Essential Eight)? If so look at transcription/script block logging/module logging settings in Group Policy (Note you can enable these on a single machine via local Group Policy, aka gpedit.msc): https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_group_policy_settings?view=powershell-5.1 If you're looking to have a kind of running-log of your PowerShell session's execution history you could add a PSConsoleHostReadLine function to your Profile.ps1. There are various automatic variables that should allow you to pull out the relevant parts of what's about to be executed and write it to a file. Note that you can break your console with this if you do something like: code:
|
# ? Apr 23, 2024 14:27 |
|
|
# ? May 4, 2024 14:38 |
|
Wizard of the Deep posted:I'm still not seeing what exactly you're trying to accomplish. Do you need to submit some kind of report of when you do a specific task? In that case, I'd honestly just auto-start a transcript as part of your profile.ps1, then grab the relevant data whenever you need to submit the report. Combine that with a Posh theme that auto-timestamps your prompt and you're probably golden. Pile Of Garbage posted:Is this potentially related to fulfilling some security thing (e.g. ACSC Essential Eight)? If so look at transcription/script block logging/module logging settings in Group Policy (Note you can enable these on a single machine via local Group Policy, aka gpedit.msc): https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_group_policy_settings?view=powershell-5.1 Thanks for the ideas. I was attending an informal training session where certain actions needed to be logged for review. I ended up just keying in ,or copy/pasting, what was needed. I have learned more about the transcripts and profiles after reading up on your suggestions.
|
# ? Apr 23, 2024 17:57 |