TFS query PowerShell script

It’s been a while since I posted any PowerShell code here, so here’s a quickie script that I’m using to help with my workflow for checking in Dynamics AX changes.

First, a little background: We have a slightly odd workflow set up in TFS for tracking the projects we do in Dynamics AX. For each project, we open a TFS work item. We then check in all changes for that project under that work item. So far, so good. But we also routinely close out a work item after the first deployment that contains a check-in for that work item. So bug fixes and enhancements after the initial deployment are technically being checked in against a closed work item.

The problem here is that the check-in dialog within AX shows a list of open work items assigned to the current user, and doesn’t provide a mechanism for searching for other work items. It does allow you to manually add a work item to the list, but it can only do that by ID. But we have our own project number, which is stored as part of the work item title, and we generally don’t use the TFS work item ID for anything, so I generally don’t know it off the top of my head. So I often have to go into Team Explorer in Visual Studio to look up the work item ID for a project before I can check it in. That’s not a huge inconvenience, but I thought it would be nice to have a little PowerShell script that could look up the work item ID for me, given an AX project number.

The script shown below isn’t terribly complicated, but it shows off a few interesting little things. I started with an example script taken from Julian Kay’s blog.

First, we’re using the TFPT command-line query capability. This is part of TFS Power Tools, and uses a query syntax called WIQL.

Second, we’re doing a little rudimentary parsing of the data returned from TFPT to pull out the first work item ID. Then, we’re copying it to the clipboard with the clip command. (Looking at this script, I’m pretty such there’s a better way for me to pull out the work item ID, but the way I’m doing it now works fine.)

And finally, we’re displaying the results to the screen, so if by chance more than one result is returned, I can see the list and decide which work item is the right one.

If I wanted to go a few steps further with this, I could probably integrate this into AX completely. The check-in dialog in AX is a regular AX form named “SysVersionControlCheckIn”, and there’s no reason I couldn’t customize it. (But that’s a problem for another rainy day.)


# Given AX project #, return ID.
param (
[string]$projno = $( Read-Host "Enter project # (e.g. 123.4)" )
)
[string]$tfpt = "C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools\TFPT.EXE"
[string]$svr = "http://myTfsServer:8080/tfs/defaultcollection"
[string]$projname = "myProjName"
[string]$query = "SELECT [System.Id], [System.Title] FROM WorkItems " +
"WHERE [System.TeamProject] = '$projname' " +
"AND [System.Title] CONTAINS '$projno' " +
"ORDER BY [System.Id] asc"
$data = & $tfpt query /collection:$svr /wiql:$query /include:data
if ($data -ne $null) {
$line = ($data | select -first 1)
$taskid = $line.split("`t")[0]
$taskid | clip
}
$data
Write-Host "Press any key to continue …"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

view raw

tfpt_ex1.ps1

hosted with ❤ by GitHub

 

Beginning SharePoint 2013 development

Beginning SharePoint 2013 DevelopmentBeginning SharePoint 2013 Development by Steve Fox
My rating: 4 of 5 stars

I’m supposed to be getting involved in some SharePoint development at work soon. But I have no details on the specific project that I’ll be working on yet. So I’ve been doing some general background reading on SharePoint, in the hopes that some of it proves useful.

This book is structured so that each chapter gives you a quick introduction to one aspect of developing for SharePoint. A lot of stuff can be considered under the general heading of “SharePoint development”, and the book tries to cover as much as it can. I think it does a good job of covering the basics, and giving a new SharePoint developer a good overview of the various ways in which a developer can interact with SharePoint.

If, like me, you really have no idea where to start with SharePoint, this is a good book to pick up and read through. It covers enough of the basics that it should get you pointed in the right direction. But it’s not going to take you very far, once you’re actually off and running.

View all my reviews

A nice day

We finally had a nice day with moderate temperatures yesterday, so I took the opportunity to make another NYC museum-hopping visit, and also did some walking. (It’s funny how my definition of “nice day” has been downwardly adjusted by this harsh winter. It was overcast yesterday, and the streets were full of melting grey slush. But it was above freezing!)

I first went to MoMA. I’m curious about their Björk exhibit, but I didn’t bother trying to get in to that. There are actually multiple parts to the exhibit; the centerpiece, I guess, is the “Songlines” exhibit, “an interactive, location-based audio experience”, which required timed-entry tickets, even for members. So, if I decide that I’m really interested in that, I’ll come back on a day when I can go in early. I’m not sure I care about a Björk exhibit that much. It seems like mostly just a novelty exhibit. But I guess stuff like that helps pay for the more interesting, less popular, exhibits, like the Toulouse-Lautrec exhibit that’s coming to an end soon.

After MoMA, I went to the Met. While I had no particular agenda for that visit, when I got there I realized there was a members preview of the Plains Indians exhibit going on, so I went in and took a look around. It’s actually really interesting and well-done.

To get some additional exercise, I walked from the Met back to Penn Station, making a quick stop at Kinokuniya. I don’t think I’d ever been in this particular Kinokuniya location before. I was surprised at how many English-language books and comics they had. They have a really good selection of American and European graphic novels on the second floor.

So it was a good day, overall. I’m looking forward to an even nicer day when all the snow is melted and the Met roof garden is open, so I can spend a little time in the sun up there, maybe enjoying a beer or coffee.

Life After Cancer

I’ve been following Federico Viticci’s site MacStories for a while now. He posts some really great in-depth and thoughtful reviews and articles. I was really blown away by his recent article about “Life After Cancer.” I don’t know much about him personally, and I had no idea that he’d had Hodgkin’s lymphoma, which is the same kind of cancer that killed my brother Pat.

Reading about his treatment, it sounds like some serious advances have been made in the last ten years, which makes me wonder if Pat would have survived if he’s gotten Hodgkin’s today rather than ten years ago. (Or maybe Federico’s case was just different from Pat’s.) There’s probably not much point in speculating.

All of his notes on the various health-related apps he’s using are quite interesting. I’m pretty well satisfied with the weight-loss app I’m currently using, LoseIt. And I use RunKeeper to track my exercise (what little I do). I’m kind of interested in the sleep-tracking app he uses, Pillow. I’d never heard of it before. I’ve been sleeping pretty well lately, I think, but I have had problems with insomnia in the recent past.

SharePoint and more

Just a quick follow-up on Saturday’s adventures with SharePoint: On Sunday morning, after letting my VM chug through 100+ Windows updates, and increasing the amount of RAM allocated to it from 1 GB to 2 GB, I eventually found myself with a barely-operational SharePoint install.

But I decided I didn’t want to spend the whole day staring at my laptop, alone in my apartment, so I turned it off and hopped on the train into New York, and spent some time at the Metropolitan Museum. Overall, I think that was a better use of my time than banging away at my SharePoint VM all day.

I spent some time this morning reading various blog posts about SharePoint development environments, and I’ve come to the conclusion that I’ll never be able to get a useful one up and running on my current hardware. With only 4 GB of RAM on my ThinkPad, there’s no way I can allocate enough to the VM. Most of the advice I’ve seen recommends 8 GB minimum for the VM, so I’d really need a laptop with at least 12 GB of actual RAM. (And some blogs indicate that 24 GB is really the reasonable minimum for SharePoint development.)

I’ve also looked at a few options for running a VM in the cloud. The one no-cost option is to sign up for a free Azure trial, and set up a VM in Azure. That might be interesting, but I don’t think the trial would be long enough to be really useful.

So I think I’m going to have to give up on the idea of setting up a SharePoint environment on my own, and wait for my new project at work to firm up a bit more. At that point, I’ll know enough about exactly what I need to do that I can make specific requests related to a specific project, and hopefully get the software/hardware I need to get up and running. Until then, I’m just going to have to settle for reading books and using my imagination!

SharePoint development

My boss told me this week that I may need to do some SharePoint development work for my next project. I don’t have any details on what exactly I might need to do, but I think it’s likely to be creating a Web Part that will interface with Dynamics AX in some way, probably through a web service. I’m well-versed at this point on the Dynamics AX side of things, but I know almost nothing about SharePoint development. So, being the proactive kind of guy that I am, I’m starting to flounder around, trying to figure out what I can about SharePoint development.

It’s not easy to get started. At work, I asked one of the other developers for some pointers, since she’s done some SharePoint work before, but since I don’t really have any details about what I’m supposed to be doing, she wasn’t much help. I don’t want to waste her time, so I’m going to hold off on asking her any more questions until I have a better idea of what I need. And, on the IT end, I had one of the SharePoint admins set up a site that I can apparently use for testing, once I’m at the point where I actually have something to deploy. But there’s not much I can do with it right now.

I have Visual Studio 2012 installed on my AX VM, so I went ahead and installed the SharePoint tools on that VM. That worked, and I now have the templates needed to create a new SharePoint web part project in VS. But, it seems that you can’t actually create a SharePoint web part project on a machine that doesn’t have SharePoint itself installed on it. Looking into it a bit further, it seems like it might be possible to do so, but it’s not obvious or simple. And that’s about as far as I got in work on Friday.

Today, I decided to see how far I could get in setting up a full SharePoint 2013 VM on my ThinkPad. I’m using VirtualBox on the ThinkPad, and I have plenty of hard drive space, so I decided to give it a go. I loosely followed the instructions in this blog post by Bill Baer, though I simplified things as much as I could. I downloaded the 180-day trial of Windows Server 2012 as a VHD. Then, I got that up and running in VirtualBox. I had to mess around with the settings a bit to get it to work, but it seems to work fine under VirtualBox, once you get the settings right. Then, I downloaded the 180-day trial of SharePoint 2013 and installed that. I hit a few snags, but nothing that I couldn’t get past with a little Google-fu. All of that downloading and installing killed most of the day. Now, the sun is about ready to go down, and I’ve got a VM that probably has a working SharePoint 2013 install on it. I say “probably” because I haven’t been about to bring it up in a browser yet. I think that’s just because the VM is running slow, and it’s taking a while to get past all the background stuff that needs to happen on a new Windows Server 2012 and SharePoint 2013 install. So, for now, I’m patiently letting it chop away at 100% CPU, hoping that eventually, it’ll settle down and become usable. There may be a few more things to straighten out though. If so, I guess I’ll be spelunking through some log files and doing some more Google-fu.

Once I’m sure I’ve got a working SharePoint 2013 install, then I’m going to have to install Visual Studio 2013. I’m hoping I can just use the free version of VS 2013, but I’m not sure. If I can’t, then I guess I have to check and see if there’s an eval version of VS 2013 Pro, or whichever version I need for SharePoint dev.

I’m not sure if the end result of all this is going to be a usable VM. The ThinkPad is a few years old. Though I did replace the hard drive with an SSD recently, it’s still only got 4 GB of RAM, and a mediocre CPU. That’s all fine for doing normal work, but it’s a little thin for powering a VM that’s got a full SharePoint install on it. So I may have to give up on this thing entirely.

I found a good blog post on how to set up an “awesome VM” for SharePoint development, but it looks like I’d need a much more powerful laptop to follow those instructions, and probably a lot more free time too. So, if the fairly basic VM that I’m trying to set up now doesn’t work out, I’ll probably give up on it for now.

Meanwhile, I’ve started reading Beginning SharePoint 2013 Development, via my company’s Books24x7 subscription. (And I ordered a used copy of the physical book from Amazon.) I haven’t gotten much useful information out of the book yet, but I haven’t gotten very far into it yet.

I went into this process knowing that I might hit some dead-ends, and knowing that I might not be able to get very far on my own. But I’m hoping that I’ll at least get far enough that I can ask the right questions when I start getting project details from my boss. I’m not sure if I’ll need to set up a new VM on my work PC with the full SharePoint install, or if I’ll be able to hook up my existing AX VM to the test SharePoint site that the admin guy set up for me. Or if I’m even going to need to do any of that at all. But, either way, I’m hoping to learn some new skills, and add “SharePoint developer” to the old resume!

taxes and reminders and things

I’m proud to say that my taxes are done, and February isn’t even over yet. (OK, I’m using an accountant now, and not doing them myself, but I’m still proud. I had to get all my paperwork together, make an appointment, show up for the appointment, etc. Yes, it was more work when I did the taxes myself, but it’s still work.)

I’m going to need to pay (federal and state) estimated taxes for 2015, though, and I’m worried that I’m going to forget one or more payments. I’d like to just set up scheduled payments through my bank or something like that, but I’m not sure that would work out. I’m sure the bank would send the money to the IRS (and State of NJ), but I’m not sure it would get credited right without the proper form attached. The IRS has something called EFTPS for electronic payments, but I don’t think I can just schedule all four payments at once and forget about it. (And I’m not sure I trust an IRS-run web site…)

So I think I’m going to have to use some kind of fancy electronic reminder system for this. A while back I mentioned that I’d been messing with Gneo and Things. Well, I pretty much gave up on both of them, and I’m just sticking with Evernote reminders for my “fancy reminder” needs. I’m sure I can create reminders for the estimated tax payments in Evernote, but I still kind of feel like I should be doing something fancier.

I’ve been listening to the Mac Power Users podcast a lot lately, but they still haven’t quite talked me into trying out OmniFocus, the fanciest of GTD / task management / reminder systems. I’m probably over-thinking this. I should just write down “pay estimated taxes” on the appropriate days on my Doctor Who wall calendar, and I’ll be fine.

no San Diego for me this year

Once again, I’ve failed to secure a badge for SDCC. Badges sold out in record time this year, so that’s not unexpected. I can probably still get a badge for WonderCon, and I may do that. I’ve been to WonderCon several times, back when it was in San Francisco. I’m not nearly as excited about Anaheim in April as I would have been for San Francisco in February (which is when they usually had the con before it moved). But it might be worth doing, just for the sake of getting out of the NY/NJ area for a few days.

I’m really not following any new comics right now, and I have pretty much no idea what’s going on in the Marvel and DC universes. And I’ve just given away most of my collection, so I’m not at all motivated to pick up any new back issues. So I’m not sure what stuff at the con would even be of interest to me, though I suspect I’d manage to enjoy myself regardless.

Of course, if the con wasn’t interesting, I could always go to Disneyland and get measles. That would be exciting!

The Humble Programmer

I ran across a reference to E. W. Dijkstra’s 1972 essay “The Humble Programmer” recently. I’d never read it before, but I like to think I already understood the concept. Any sort of serious programming job is going to reinforce a programmer’s humility on a fairly regular basis, unless the programmer in question is incredibly good, or incredibly deluded.

The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.

At my current job, for the ERP system I work on, we do production deployments once a week, usually. We may do a post-deployment fix or supplemental deployment occasionally, but usually only if a really show-stopping bug made it in. (The deployment process is apparently time-consuming and arcane. I don’t really know how it’s done, exactly, but I think it involves ritual animal sacrifice and long incantations from the Necronomicon.)

I managed to introduce two exciting bugs into the system in last week’s deployment. So this week’s deployments include:

  1. A fix to a problem that I knew would occur, under a certain set of circumstances, but which I thought would probably only occur once in a blue moon, if ever. Instead, it happens about 20 times a day. One user referred to it as “really really really frustrating” and “a horrible inconvenience” in a support ticket she opened.

  2. A fix to a problem that had never even once occurred in testing, and which I have still never been able to recreate in testing. In production, of course, it happens about 10 times a day. And since I still haven’t been able to recreate the issue in the test environment, I can’t really be sure if the “fix” actually fixes the problem.

So, basically, my errors have been annoying the heck out of our users for the last week, and I have once again been reminded that I am fallible, sometimes spectacularly so!