Last active
December 3, 2024 19:34
Revisions
-
gitfvb revised this gist
Dec 2, 2024 . 1 changed file with 25 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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]{ param ($counter, $removeColumnPrefix, $logfile) Get-Counter $counter -Continuous -SampleInterval 10 | ForEach-Object { $o = [ordered]@{ "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ") } $_.CounterSamples | ForEach-Object { $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue ) } [pscustomobject]$o } | Export-Csv -Path $logfile -Encoding UTF8 -NoTypeInformation -Append } # 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 ``` -
gitfvb revised this gist
Dec 2, 2024 . 1 changed file with 35 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,15 +14,45 @@ Show all available processes get-process | Out-GridView -PassThru ``` Get all counters of a teams process every ten seconds ```PowerShell $procCounter = get-counter -listset "Prozess" | % { $_.Counter } get-counter $procCounter.replace("*", "ms-teams") -Continuous -SampleInterval 10 ``` This is the most advanced example to create a flat table with the process counters every 10 seconds ```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 } ``` 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 ``` -
gitfvb revised this gist
Dec 2, 2024 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ``` -
gitfvb revised this gist
Dec 2, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
gitfvb revised this gist
Dec 2, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
gitfvb created this gist
Dec 2, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ```