-3

Is there a way to automatically take one or a series of screeshots to capture the entire output of a powershell command? It would be nice to be able to see the original command and / or the powershell window.

This is needed in order for a government compliance team who find comfort in that a picture is more work to alter than text output.

This New-Screenshot function looks promising but it uses print screen to save the image to the clipboard. Another method looks very promising where they capture ALL the text in the buffer $Host.UI.RawUI.GetBufferContents.

Steps to automate

  1. [Done] Run clear
  2. [Done] Run the command
    • possibly pipe the command to more to see it paginated
  3. [Done] Hit print screen for just the command window and save to a file
  4. Scroll down to the next page and repeat step 3 until the output has been completely captured
  5. Cat all the images into a single image.
  6. Repeat step 1 and run the next command until complete.

The other way to do it is to make the text reaaaally small to get it to fit in a single window. I'd much rather prefer the first solution but I cannot find a way to scroll a window via Powershell.

SomeGuyOnAComputer
  • 5,414
  • 6
  • 40
  • 72
  • 1
    Find a screenshot application you like, find a way to automate it. – Maximilian Burszley Jan 10 '19 at 18:23
  • What about using [Start-Transcript](https://learn.microsoft.com/de-de/powershell/module/Microsoft.PowerShell.Host/Start-Transcript?view=powershell-5.1) ? –  Jan 10 '19 at 18:31
  • @LotPings unfortunately that command outputs a text file when the compliance team requires an image. Thank you for the suggestion. – SomeGuyOnAComputer Jan 10 '19 at 18:49
  • I've updated the question to show I'm looking for a way to scroll a command and then have another powershell script capture screenshots. Would that be enough to remove your downvote @TheIncorrigible1 ? – SomeGuyOnAComputer Jan 10 '19 at 18:49
  • is the output colored/formatted and is that important? May be do text output and then use text-to-image tool which would be easier to automate? – Max Jan 10 '19 at 20:48
  • alternatively, you may use a PDF-printer and print your output. or use something like Virtual ImagePrinter to produce your output as image – Max Jan 10 '19 at 20:51
  • Unfortunately they would not like that as thats based on text... these compliance issues are a real bother. Thanks for the suggestions though. – SomeGuyOnAComputer Jan 10 '19 at 22:22

1 Answers1

1

Why are you not using the built-in Windows PSR tool?

That is what it is in Windows for to capture real-time as you click anywhere on the screen.

Windows Problem Steps Recorder (PSR): quick and easy documenting of your steps and procedures

Problem steps recorder is a tool that is available in Windows since Windows 7 (client) / Windows 2008 R2.

In this blog post Jump , you'll be able to find more details on PSR (or Problem Steps Recorder).

In short:

• It's a built-in Windows tool, that
• allows to screen-capture on mouse-click
• and add comments to it

Though the link talks about legacy OS, it is still in every current Windows OS version This saves to a .htm file that can be viewed in any browser.

Or If you are bent on doing this with PowerShell, see this script.

Automating Screenshots with PowerShell

<#
.SYNOPSIS

    Get-TimedScreenshot

    Author: Chris Campbell (@obscuresec)
    License: BSD 3-Clause

.DESCRIPTION

    A function that takes screenshots and saves them to a folder.

.PARAMETER $Path

    Specifies the folder path.

.PARAMETER $Interval

    Specifies the interval in seconds between taking screenshots.

.PARAMETER $EndTime

    Specifies when the script should stop running in the format HH-MM 

.EXAMPLE 

    PS C:\> Get-TimedScreenshot -Path c:\temp\ -Interval 30 -EndTime 14:00 

Yet even with this, you now have to assemble this in to a word doc and the link or look at each manually to get the shot you'd want.

Update for the OP

As for …

A timed screenshot could work but I'd have to find a way to automate scrolling down until the end of the output.

… you could just use Sendkeys pagedown (I know, I know, sendkeys are a hack) or take a look at using selenium-powershell for additional GUI automation of whatever screen you are targeting. WASP is still also and option, though no longer worked on.

postanote
  • 15,138
  • 2
  • 14
  • 25
  • This is pretty close. The reason why I suggested powershell is because I need to run the commands on windows and I'd like to automate this as I'm sure we'll be asked to supply this information again. A timed screenshot could work but I'd have to find a way to automate scrolling down until the end of the output. – SomeGuyOnAComputer Jan 10 '19 at 22:24
  • Interesting idea with GUI automation but then why not just use [powershell to do the same](https://stackoverflow.com/a/39132975/2965993)? – SomeGuyOnAComputer Jan 11 '19 at 00:19
  • Native PowerShell is not the tool for GUI automation as directly noted in the link you point to. You can, but it can / will be fraught with unnecessary hair-pulling. Sendkeys using WShell or [System.Windows.Forms.SendKeys], and then these things act differently on different machines. Sure, you can do it, doing it reliably / consistently, is a different conversation. Yet, it's up to you of course. There are purpose built tools for this GUI automation stuff the above and https://www.autoitconsulting.com/site/scripting/autoit-cmdlets-for-windows-powershell. – postanote Jan 11 '19 at 00:39