Skip to Content
Personal website of Steven Peck. Focusing on Drupal, Microsoft technologies (most notably PowerShell), and other random bits I think to write.

Using PowerShell to add numbers in a text file

Recently had a conversation where someone needed help adding up the last column in a tab separated text file. It looked like a calling plan report. In channel tons of people brought up all sorts of *nix based tools which I thought odd since it was a Windows based IRC channel.

I've occasionally had a need for something like this anyway so poked at it for a few minutes and came up with the below one liner which I will leave here so my bad memory can find it again.

import-csv .\test.txt -Header "date","something","type","cost" -delimiter "`t" | Measure-Object cost -sum
 
Count    : 12
Average  :
Sum      : 2.38
Maximum  :
Minimum  :
Property : cost

Since the text file doesn't have any header rows, you have to 'add them' through the import command.

Here is that test.txt file example.

14-Dec-11 	0-234 	Long Distance 	0.32
14-Dec-11 	0-960 	Long Distance 	0.04
09-Dec-11 	1-237 	Directory Assistance Call Comp 	1.25
09-Dec-11 	1-960 	Directory Assistance Call Comp 	0.15
22-Nov-11 	0-234 	Long Distance 	0.12
22-Nov-11 	0-960 	Long Distance 	0.01
16-Nov-11 	0-234 	Long Distance 	0.16
16-Nov-11 	0-960 	Long Distance 	0.02
12-Nov-11 	0-234 	Long Distance 	0.20
12-Nov-11 	0-960 	Long Distance 	0.02
11-Nov-11 	0-234 	Long Distance 	0.08
11-Nov-11 	0-960 	Long Distance 	0.01

Update:
A user (spade) in #PowerShell contributed this approach as well.

gc data2.txt | % {$sum=0} { $sum += ($_ -split "`t")[-1] } { $sum }

Family Support Plan Rules

Like anyone who works with computers and has friends and family, I get asked to do friends and family support. One thing I've learned is that even this type of support needs rules, or you end up spending way to much time that isn't valued.

Here are my rules.

  1. I must agree to this ahead of time so I can supply you with the rules and aid you into migrating to a supported configuration (which may include a wipe and reload).
  2. I do not support your bad habbits therefore you may not run as an Administrator with your every day account and you may not disable UAC.
  3. You must run Windows 7 (I am forgetting Windows XP basics and people say silly things about Vista).
  4. Must have Windows Update enabled.
  5. All your software must be licensed.
  6. Must have anti-virus (Microsoft Security Essentials)
  7. Should run Secunia PSI.
  8. Must have a data backup strategy.
    • Minimum sync to SkyDrive
    • Something like CrashPlan
    • Everyone says they don't have any important data until it's gone. I don't want to listen to you complain about it missing if something goes horribly wrong like a hardware failure or theft. Think pictures (baby pictures, etc)
  9. If you call me, you must be available. If you are not keeping me company I will wander off. You must be available to make decisians and entertain me (also to answer questions about what happened).
  10. If you ask my advice on a hardware purchase and then 'cheap out' with a low end piece of junk, do not expect sympathy. If you are on a budget feel free to tell me your range and needs and we'll work together to find something that should last you a few years.

So far this has successfully kept family system support issues to a minimum in the last two years. Pretty much a quick check while visiting for holiday/events or an occassional advice on new hardware.

PowerShell-Windows.Forms RDP Launcher

In a given environment there can be many short term solutions that over time grow into long term headaches. We have a situation where we need to provide access to RDP sessions through Citrix. The original solution by previous admins was to create a custom RDP icon configured to the server in question and publish it in Citrix. This resulted in a rather 'busy' screen in Citrix and intermittant update issue.

A co-worker asked about PowerShell doing this and I said something off handed about Windows Forms to generate a menu selection should be do-able. He found a nice Windows.Forms example and then did a hard coded elseif menu (which seemed as bad as all the links to me). I came up with an improvement where we pulled the server/ip list from a file and used Select and Eric Woodford added a nicer $choice option with the added bonus of turning the line for launching RDP into a variable. This is good because we have a similar issue with putty links. This should wipe out 80 some odd custom published Citirx apps.

SIM IE9 Trusted Sites

HP SIM with IE9 really wants it to be in the Trusted sites list for some functioanlity to work reliably. However, maybe there is a GPO preventing you from adding to the trusted sites list yet you need to get to something 'now'. Grrr...

Let's go with a hypothetical SIM server of SimServerName.

PowerShell launched with administrator credentials (you can do this manually too)

Why I don't buy Android

Came across this link on Android Orphans: Visualizing a Sad History of Support. This shows as a visual the reality of what happens in the Android eco-system. The iPhone has the advantage of being owned as a vertical platform across it's hardware and software (I rather dislike iTunes so it's not really an option for me).

While the Windows Phone is not on the chart, as a contrast we have this post Updates: Windows Phone 7.5 now available more broadly. This shows how much effort it is to have a diversity of hardware platforms yet a consistency of versions in a global market yet they are doing it. Add in things like the integrated hubs and that everything just flows together more seemlessly for me, it ends being the obvious choice.

Microsoft continues to travel a path of having all it's users have a consistent core experience, yet still maintain a diversity of hardware choice.

Found via Android Orphans: Visualizing a Sad History of Support

Windows Phone and Google calendars workaround

I like my Windows Phone and the Mango release is definitly making it better. One irritation is Google being petty and preventing the view of calenders to which I have permissions too. Here is the user agent string with Chrome and the link to the instructions I used to work around this.

chrome.exe --user-agent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3 like Mac OS X; en-gb) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5"  -disable-javascript

Mango Tip: Sync Multiple Google Calendars with Windows Phone

Syndicate content