How to compress a file using PowerShell
June 23rd, 2010
A friend asked how to set compression on a file using PowerShell. It took a little digging and a few wrong turns but it turns out to be quite simple:
$file = Get-WmiObject -Class CIM_DataFile -Filter "Name='c:\\temp\\test.txt'"
$file.Compress()
Cheers, Dan
Get notifications when The Current changes songs
May 13th, 2010
This is totally unrelated to work but is awesome with a capital A. If you like The Current then you’re going to love this tip. First of all, what is The Current? It is only the best radio station on the planet. Take a minute to go check them out at http://www.thecurrent.org/ .
So now you’ve checked out The Current and love them. You can listen to them over the air waves via 89.3 FM, over their iPhone/iPad app available on iTunes , over LIVE streaming available on their web site or LIVE streaming available via the Internet Radio stations listed in iTunes or Apple TV ( under the Alternative section ). You really have no reason to NOT listen to them!
I used to use The Current’s LIVE streaming via their web site to listen to their broadcast. There was one problem with this – whenever I hear a song I like that I don’t know the artist/title I have to switch over to the web browser to see who it is. That get’s a little annoying but that’s a good thing… because they play a ton of new stuff that is really good. However, I’m ecstatic because I found a solution to this problem.
I keep my music in iTunes and have been using Growl and GrowlTunes to get popup notifications when the next track plays. Tonight I had the idea to listen to The Current in iTunes while running GrowlTunes to see if I would get a popup notification when they change tracks on the radio station. So I fired up GrowlTunes and iTunes and then found The Current in the Alternative station list and what do you know!! I started getting popup notifications from Growl whenever The Current played a new track. Yay!! Happy listening folks!
The Current is supported by members so if you like them please support them by sending them a little cash – seriously… everybody knows you could do with a one or two less cappuccinos each month – so do your friends a favor and give it to The Current instead.
This article applies to iTunes and Growl running on Apple Mac OS X. Sorry Windows friends… I’m not sure if there is a way for you to do this or not. If any Windows friends find a way please email me and I’ll update this article – just send a message to dan@humanstuff.com.
Cheers, Dan
Get scheduled tasks in PowerShell
March 30th, 2010
If you need to get info about scheduled tasks on a system in PowerShell, the schtasks command has a nice switch called ”/FO” that makes it easy to get the results in a PowerShell friendly format:
$tasks = schtasks /query /v /fo CSV | convertfrom-csv
How to add the current user to the PowerShell window title bar
July 24th, 2009
I use PowerShell for a lot of administrative functions. So for different environments I have different administrative accounts that I run the PowerShell window as. When I have a few of these windows open at the same time it is hard to remember which window is for which environment. A simple solution to this is to add the domain and user id to the window title bar so it is easy to determine which environment or user account I’m working with.
You can do this manually by setting the property $host.UI.RawUI.WindowTitle . I don’t like this though because it becomes tedious to do every time you open a window. To fix that problem you just need to add a little script to a PowerShell profile and your done.
I added the following script to %windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 and now it is easy for me to remember which account I’m running under.
$h = get-host
$title = $h.UI.RawUI.WindowTitle
$h.UI.RawUI.WindowTitle = "$title ($($env:userdomain)\$($env:username))"
ThoughtWorks Decides Against Mingle SaaS
March 12th, 2009
We are currently reviewing solutions for managing our projects. Mingle is one candidate. Mingle is an agile project management product created by ThoughtWorks Studios. I have used it in the past on projects at 3M and Inetium and I really liked it. On those projects, however, I had the luxury of an internal network infrastructure and a team to maintain it.
At HumanStuff, we strive to keep our overhead low and outsource things that are not part of our core business. This enables us to stay focused on our bread and butter – providing high quality software consulting services to our customers. So one key consideration when reviewing project management solutions is whether or not it is offered as a hosted solution or Software as a Service (SaaS) so we don’t have to manage the infrastructure.
I have made a few attempts to try to find out if Mingle would be offered as a service. I finally received confirmation today from a ThoughtWorks representative the answer is no. This information was surprising given the number of articles I found stating the contrary (e.g. InfoQ). This makes the decision to choose Mingle as our project management solution much more difficult and will probably eliminate it as a candidate.
What do you think about Mingle not being available as a service? Are there a number of people who would be interested in this or are all of you Minglers just hosting it yourself?
Experts Exchange
December 16th, 2008
I really hate Experts Exchange - I'm not even going to provide a link to them because I don't want to help their page rank. Please do not sign up for this site. They take content normally available through other (free and hassle-free and pester-free) channels and hold it hostage so they can get your personal information and sell you ads. They have a right to do it. I have a right to hate it.
I created a javascript link that I use for tech searches that will pass the "-site:experts-exchange.com" parameter so I can prevent their hijacked content from popping up in my search results. If you want that link just drag this link Search Google (no EE) to your browser toolbar to use it too.
Joe McRae
December 16th, 2008
In work, or even life in general, you don’t meet many people that you are better off having known. My uncle collectively referred to these people in general as “the good guys”. Well Joe is one of the good guys. Thanks, Joe, for everything you do.
Use of the "this" keyword
August 29th, 2008
Pubb just posted this tweet “in your c# code: this. or no this.? why?” and my reply was too long for Twitter so I’ll post it here.
The “this” keyword refers to the current instance of the class. When a variables in the local scope have different names than the instance fields the “this” keyword can be used to differentiate an instance field from a variable (or input parameter) in the local scope. If an input parameter has the same name as the instance field then you are required to use the “this” keyword to access the instance field.
Some developers prefer to use a prefix on instance fields such as an underscore “” or “m” to differentiate them from other variables. In this case I think the use of “this” is redundant and should be omitted.
I prefer to follow the .NET Design Guidelines Field Usage Guidelines which states “Do not apply a prefix to field names or static field names” so I don’t have “” or “m” prefixes on my instance fields. If I am accessing a field from other members I try to keep those members short enough so that you can clearly see the definitions of all variables/parameters without scrolling which makes it very easy to determine what is a local variable or input parameter and what is an instance field. In this case I only wind up using “this” in my constructors if the input parameters to the constructor have the same name as the instance field.
PowerShell - Get lines from middle of file
August 1st, 2008
I have been digging through log files to try to find information about errors that I’m troubleshooting. I start out with some information that I’m searching the log files for. For example:
# find the troublesome user
$occurrences = ls -r -i *.log | select-string 'Dan'
Great. Now I have an array of Microsoft.PowerShell.Commands.MatchInfo objects in my $occurrences variable. The MatchInfo has the following members (some members removed for clarity):
TypeName: Microsoft.PowerShell.Commands.MatchInfo
RelativePath Method System.String RelativePath(String directory)
Filename Property System.String Filename {get;}
IgnoreCase Property System.Boolean IgnoreCase {get;set;}
Line Property System.String Line {get;set;}
LineNumber Property System.Int32 LineNumber {get;set;}
Path Property System.String Path {get;set;}
Pattern Property System.String Pattern {get;set;}
Now I want to run through all the matches and take a peek at the 20 text lines above and below the match like this:
# show the context around each match and pause
$occurrences | %{ (get-content $_.Path)[$($_.LineNumber - 20)..$($_.LineNumber + 20)]; pause; }
Pause is not a built-in command. I’m using the pause function described here Pause on PowerShell Team Blog
Are there broken windows in teams?
July 28th, 2008
The pragmatic programmers wrote an article titled Software Entropy that discussed the concept of a “broken window” in software.
The gist of the article was that, when coding, there are things in the code that you know are not right and that you should fix them. If you don’t fix them it will lead to an overall perception that the quality of the software is not great but that state is acceptable. This perception will spread throughout the project and other developers will allow other quality issues to pass and eventually the total quality of the system will suffer. I believe that the authors highlight a very important human behavior here.
Notice that I didn’t say coder or developer behavior but I said human behavior. I believe that the observations are founded and that the behavior pertains to people as a whole. The reference to research on crime and urban decay support this belief. Suppose for a moment that this is true. If so, then that leads me to ask myself the question “Are there broken windows in teams?”
I think there are definitely broken windows in teams. What do I mean by that, you might be asking. Have you ever been on a team where someone wasn’t contributing to their full potential and everyone knew it? Have you ever been on a team where someone was extremely negative or corrosive and was creating a bad team chemistry? Have you ever been on a team where someone was arrogant and aggressive?
I think these are broken windows too. If you don’t do something about it then the total quality of your team will suffer and I believe this will surely affect the total quality of the solution too. If you have a cancerous person on your team you need to turn them around, isolate them, or send them packing.
Make your views stupid
April 11th, 2008
I’ve been working on a project that is using a Model-View-Presenter pattern. I’ve noticed something in the view code that I want to write a quick post about: views that are way smarter than they should be.
The presenter represents the workflow or process that the user is working on. It encapsulates the state of a use case instance. It has the responsibility of responding to the user’s interaction. The view simply displays data and sends messages back to the presenter when the user interacts with an element in the view.
If you have code like this in your view:
| // some button click event handler |
| presenter.DoSomething(); |
| presenter.RefreshTheView(); |
then you have a bad smell. It should look like this:
| // some button click event handler |
| presenter.DoSomething(); |
| // presenter’s code |
| public void DoSomething() |
| { |
| // build a request from the view data |
| // do something |
| // refresh the view |
| this.RefreshTheView(); |
| } |
Unless you have a lot of formatting to do in the view, your view should be comprised of a lot of one line method calls back to the presenter (or preferably raised events). The presenter should tell the view “show this to the user” and, optionally, “action XYZ is not available”. The view should tell the presenter “the user did something”. I like to specify this as events on the view interface so the complete communication contract is documented in one spot – but that’s another post.
We're back
April 11th, 2008
Hi, all. John and I took the blog down for a while since we weren’t doing much blogging at the time. We both despise blogs that stagnate and ours was becoming one so we decided to take it down for a while. A lot has happened since then.
The short story is that John and I used to work at a company called Inetium . It was there that we started working on HumanStuff as a concept or hobby company. In December John and I made HumanStuff a reality. We are providing consulting services in the Twin Cities. We still have plans for developing products as well but that will be secondary to consulting.
It is currently just the two of us. However, hiring is in our plan so we’ll keep you posted. I think the interview process will be sitting down and writing a simple application given a set of requirements (see “How to hire a juggler” in Peopleware ) but we’ll see.
I’ll be blogging about the experience of building the business, development, stuff we’re working on, etc. If you have tips on how to improve the blog please send me an e-mail at yourblogsucks (seriously – I have an address set up for that and am looking for feedback) at humanstuff dot com.
Cheers, Dan

