Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Last active December 3, 2024 19:34

Revisions

  1. gitfvb revised this gist Dec 2, 2024. 1 changed file with 25 additions and 6 deletions.
    31 changes: 25 additions & 6 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -32,6 +32,7 @@ get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval
    If you want to write it directly to a csv file, use it like this one

    ```PowerShell
    $procCounter = get-counter -listset "Prozess" | % { $_.Counter }
    $processName = "ms-teams"
    $removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
    get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % { $o = [ordered]@{ "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ") }; $_.CounterSamples | % { $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue ) }; [pscustomobject]$o } | Export-Csv -Path ".\teams-log.csv" -Encoding UTF8 -NoTypeInformation -Append
    @@ -40,19 +41,37 @@ get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval
    To run this job in the background (e.g. if you are running a remote rdp session), you can put this in a scriptblock and run it separately

    ```PowerShell
    $procCounter = get-counter -listset "Prozess" | % { $_.Counter }
    $processName = "ms-teams"
    $counter = $procCounter.replace("*", $processName)
    $removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\" # this could also be done more dynamically
    $logfile = "C:\Users\Florian\teams-log.csv" # better use an absolute path as the job is not starting at your users home directory
    # The script loop the fill the logfile
    $sc = [scriptblock]{
    $processName = "ms-teams"
    $removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
    $logfile = ".\teams-log.csv"
    get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % {
    param ($counter, $removeColumnPrefix, $logfile)
    Get-Counter $counter -Continuous -SampleInterval 10 | ForEach-Object {
    $o = [ordered]@{
    "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ")
    }
    $_.CounterSamples | % {
    $_.CounterSamples | ForEach-Object {
    $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue )
    }
    [pscustomobject]$o
    } | Export-Csv -Path $logfile -Encoding UTF8 -NoTypeInformation -Append
    }
    Start-Job -ScriptBlock $sc
    # Start a new background job
    Start-Job -ScriptBlock $sc -ArgumentList $counter, $removeColumnPrefix, $logfile
    # View the current status of jobs
    Get-Job
    # Stop the job with a specific id like
    Stop-Job -Id 5
    ```
  2. gitfvb revised this gist Dec 2, 2024. 1 changed file with 35 additions and 5 deletions.
    40 changes: 35 additions & 5 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -14,15 +14,45 @@ Show all available processes
    get-process | Out-GridView -PassThru
    ```

    Show network data of
    Get all counters of a teams process every ten seconds

    ```PowerShell
    get-counter -Counter "\Prozess(ms-teams)\E/A-Bytes gelesen/s" -Continuous | ft
    $procCounter = get-counter -listset "Prozess" | % { $_.Counter }
    get-counter $procCounter.replace("*", "ms-teams") -Continuous -SampleInterval 10
    ```

    Get all counters of a process every ten seconds
    This is the most advanced example to create a flat table with the process counters every 10 seconds

    ```PowerShell
    $procCounter = get-counter -listset "Prozess" | % { $_.Counter }
    get-counter $procCounter.replace("*", "ms-teams") -Continuous -SampleInterval 10
    $processName = "ms-teams"
    $removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
    get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % { $o = [ordered]@{ "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ") }; $_.CounterSamples | % { $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue ) }; [pscustomobject]$o }
    ```

    If you want to write it directly to a csv file, use it like this one

    ```PowerShell
    $processName = "ms-teams"
    $removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
    get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % { $o = [ordered]@{ "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ") }; $_.CounterSamples | % { $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue ) }; [pscustomobject]$o } | Export-Csv -Path ".\teams-log.csv" -Encoding UTF8 -NoTypeInformation -Append
    ```

    To run this job in the background (e.g. if you are running a remote rdp session), you can put this in a scriptblock and run it separately

    ```PowerShell
    $sc = [scriptblock]{
    $processName = "ms-teams"
    $removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
    $logfile = ".\teams-log.csv"
    get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % {
    $o = [ordered]@{
    "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ")
    }
    $_.CounterSamples | % {
    $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue )
    }
    [pscustomobject]$o
    } | Export-Csv -Path $logfile -Encoding UTF8 -NoTypeInformation -Append
    }
    Start-Job -ScriptBlock $sc
    ```
  3. gitfvb revised this gist Dec 2, 2024. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Documentation: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-counter?view=powershell-5.1

    Show all available counters, be careful, this seems to be language dependent

    ```PowerShell
    @@ -11,3 +13,16 @@ Show all available processes
    ```PowerShell
    get-process | Out-GridView -PassThru
    ```

    Show network data of

    ```PowerShell
    get-counter -Counter "\Prozess(ms-teams)\E/A-Bytes gelesen/s" -Continuous | ft
    ```

    Get all counters of a process every ten seconds

    ```PowerShell
    $procCounter = get-counter -listset "Prozess" | % { $_.Counter }
    get-counter $procCounter.replace("*", "ms-teams") -Continuous -SampleInterval 10
    ```
  4. gitfvb revised this gist Dec 2, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@ Show all available counters, be careful, this seems to be language dependent
    ```PowerShell
    get-counter -listset * | Out-GridView
    get-counter -listset "*Netzwerk*" | fl
    get-counter -listset "*Netzwerk*" | % { $_.Counter }
    ```

    Show all available processes
  5. gitfvb revised this gist Dec 2, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@ Show all available counters, be careful, this seems to be language dependent

    ```PowerShell
    get-counter -listset * | Out-GridView
    get-counter -listset "*Netzwerk*" | fl
    ```

    Show all available processes
  6. gitfvb created this gist Dec 2, 2024.
    11 changes: 11 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    Show all available counters, be careful, this seems to be language dependent

    ```PowerShell
    get-counter -listset * | Out-GridView
    ```

    Show all available processes

    ```PowerShell
    get-process | Out-GridView -PassThru
    ```