Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Historically Speaking

Posted on November 24, 2015November 24, 2015

So I've recently had a need to begin using Slack. I started out using a web browser, but since there is a Windows client I decided to give it a go. This article isn't about Slack as much as what I was curious about and how I decided to tackle the problem.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I had read a few comments about the performance of the Slack client, although they may have been in reference to using a web browser, but it actually doesn't matter. Instead I thought, "How can I get some historical data?" You probably have similar needs for things like processes or disk space. Since I was interested in memory utilization I could have used performance counters, and perhaps I'll write about that eventually, but for now I had a simple one line command that gave me the pieces of information I wanted to track.

Get-Process Slack | measure -Property WS -sum | Select Count,Sum

Getting process dataGetting process data (Image Credit: Jeff Hicks)

What I wanted was a way to take that snapshot repeatedly throughout the day and record the results. I decided to use a PowerShell scheduled job.

I wanted a repeating task and in my case I decided to only have it repeat for an 8 hour time span. I used a hashtable of parameters to splat to New-JobTrigger.

$paramHash = @{
RepetitionInterval = (New-TimeSpan -Minutes 30)
RepetitionDuration = (New-Timespan -hours 8)
at = (Get-Date).AddMinutes(1)
Once = $True
}

$Trigger = New-JobTrigger @paramHash

I elected to kick off the job one minute from the time I created the trigger. I could have used a scriptfile for my command which I expanded to export the results to a CSV file with a little additional information.

$sb = {
Param([string]$Path)

Get-Process Slack | measure -Property WS -sum |
Select @{Name="Computername";Expression={$env:computername}},
@{Name="Date";Expression={Get-Date}},Count,Sum |
Export-CSV $path -Append -NoTypeInformation
}

All that remains is to create the scheduled job with Register-ScheduledJob.

$path = "C:\work\slackhistory.csv"
$paramHash = @{
Name = 'SlackHistory'
Trigger = $Trigger
MaxResultCount = 4
ScriptBlock = $sb
ArgumentList = $path
}

Register-ScheduledJob @paramHash

Throughout the day, PowerShell added data to my CSV file.

The data csv fileThe data csv file (Image Credit: Jeff Hicks)

If you noticed, I suppressed type information. This was so I could easily import the CSV into Excel and do some charting.

Charting the data in ExcelCharting the data in Excel (Image Credit: Jeff Hicks)

I formatted a few columns to make a nicer graph. Although I certainly could have formatted values like the WS sum in MB in PowerShell to begin with.

My techniques here are admittedly a little ad-hoc and perhaps not completely ready for an enterprise wide data gathering system, certainly of the "poor man's" flavor. But I hope you see how easy it is to combine PowerShell and scheduled tasks to get the job done.

You probably have questions, so feel free to ask in the comments.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

1 thought on “Historically Speaking”

  1. David Stein says:
    November 24, 2015 at 11:19 pm

    Nice! Thanks for sharing this!

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d