Powershell header unaffected by scolling possible ?

Synthetic-Sentience 11 Reputation points
2022-02-18T15:58:58.32+00:00

Hi

I'm looking to have my Powershell scripts have a header that stay's persistent and is unaffected by the output scrolling.

Similar to how we would freeze panes / freeze top row in excel.

I'm wondering how I would go about this.

I'm thinking Powershell studio may have this ability but I'm not sure. Only see forms nothing about scrolling.

Perhaps Visual studio code can do this.

Perhaps it's not possible to do easily ?

Thanks for reading

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,513 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MotoX80 33,376 Reputation points
    2022-02-19T15:14:53.73+00:00

    Would out-gridview accommodate ?

    I don't think so.

    Sounds like Write-Progress might be what you are looking for.

    while ($true) {
        $p = Get-Process
        Write-Progress -Activity “Collecting Processess” -status “We found $($p.count) processes." 
        $p
        Start-Sleep -Seconds 5
    }
    
    1 person found this answer helpful.
    0 comments No comments

  2. MotoX80 33,376 Reputation points
    2022-02-18T16:20:40.097+00:00

    One option is Out-Gridview. Here is a script that I put together to gather records from all event logs for a given timeframe and puts them in TOD sequence.

    # Name: RecentEvents.ps1
    # Desc: Script to read all event logs and put all events within a timeframe into TOD sequence.
    #       The intent is to see all events that occurred at a certain time when an error may have occurred.  
    #       Life was simpler when we only had 3 eventlogs. 
    # Usage: RecentEvents.ps1 NumberOfHours    Ie:  RecentEvents.ps1 24
    # Author: Dave (MotoX80)
    param($tf = 1 )          # Time frame in hours. 
    $hdr = $tf
    $tf = $tf * 3600000
    $elna = (Get-WinEvent -ListLog * -EA silentlycontinue | where-object { $_.recordcount -gt 1})     # get all event log names that have records in them. 
    $AllEvents = @()              # prepare array so we can append to it
    foreach ($el in $elna)        # look at each event log
    {
        $xml = "<QueryList><Query Id=""0"" Path=""$($el.logname)"">
                <Select Path=""$($el.logname)"">*[System[TimeCreated[timediff(@SystemTime) &lt;= $tf ]]]</Select>
                </Query></QueryList>"       
        $AllEvents += Get-WinEvent -FilterXml $XML -ErrorAction SilentlyContinue  # append the events (if any)
    }
    $AllEvents | sort-object -Descending -Property TimeCreated  | 
    Select-Object -property TimeCreated, ID, Logname,  LevelDisplayName, Message |
    Out-GridView -Title "Recent Events ($hdr hours)" 
    
    0 comments No comments

  3. Synthetic-Sentience 11 Reputation points
    2022-02-19T14:06:31.36+00:00

    Thanks for that. I'm looking to have the header contain some info that would dynamically change such as Loop count, detections made, Date/time each loop started.

    Would out-gridview accommodate ?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.