Category Archives: windows

find and delete duplicate files with just Powershell

... analog computer!

Consider this. You have the same files with different file names spread out over a bunch of folders. If you are on a recent Windows machine, Powershell is all you need to get out of that mess and delete the duplicates.
This also means you get to do this from the command line which makes it extra l33t.

Cool. Let’s get started.

ls *.* -recurse | get-filehash | group -property hash | where { $_.count -gt 1 } 
| % { $ | select -skip 1 } | del

You’re done.

Alright. Here’s what going on in detail:

ls *.* -recurse             # get all files in the current folder and all subfolders
get-filehash                # calculate the file hash for all files
group -property hash        # group them by the hash value
where { $_.count -gt 1 }    # select those groups with more than 1 item
% {                         # for all groups
    $ |              # output the group content, which are the files
    select -skip 1          # select all but the first file 
   }                        # (we don't want to delete all of them right?)
del                         # delete the file

If you want to experiment with this I’d recommend you to change the last del command with something safer, like echo which just prints out the file or by adding the -WhatIf parameter so simulate a delete.

Oh yeah, **DISCLAIMER**. Don’t just randomly copy past Powershell code and execute it on your machine if you don’t know what you are doing. Certainly if it’s deleting files like the example above. You might end up deleting more than you bargained for.  :)

Photo by James Vaughan, cc-licensed.

how to get code from tfs from the command line

Green blurry command line shots are so cyber.

Ever wanted to pull an update from the TFS server for all workspaces you have without having to start up the Visual Studio? Well I did. Visual Studio is rather slow in starting up and then you have to navigate to the TFS explorer (clicky clicky) and manually update the workspaces (clicky clicky) and then wait till the whole thing is done and VS becomes responsive again (waity waity).

You have the tf.exe command which you can use from a command prompt, but that requires you to use the VS command line because the right paths are set there. You could set the paths so they are available in all your shells, but that’s not very handy either.

I just wanted a batch script that I could run from any shell, that would just update my workspaces for me. Nice and easy.
Like when I press CTRL-R in Windows (Run) and type getfoo.cmd<enter>, it just makes it all happen for me.

So here’s how I did that:

@echo off


:: Importing VS 2012 command line variables so we can run TF.exe
if exist "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat" (
echo Importing VS 2012 environment variables...
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"

echo *** Updating TFS workspaces ***

:: Repeat this for all workspaces you want to update.
cd D:\WS\pathtosolutionfiles\

tf get . /version:T /recursive

echo *** Workspace updated. ***

windows rescue kit on a usb stick

Attempt Repair Install

While cleaning up an old machine I was first using CCleaner from Windows to wipe some partitions because DBAN crashed for some reason on it. To clean some of the Linux partitions on the drive which Windows can’t access, I dropped them so I could re-add them as NTFS partitions for further wiping. Problem was I forgot those partitions where also hosting my master boot record, so when I rebooted to confirm my partition changes… I ended up with a unbootable system.


Now I had to find a way to wipe those disks from Linux, but first I still wanted to get access to my WinXP setup. I could have just nuked it from orbit (read: boot from a Linux Live CD and shred it) but I was just wondering if I would manage to get it to boot again, just in case I do this on a system that really matters some day. So I started browsing to the ISO’s available on the Universal USB Boot installer and ran into the awesome Trinity Rescue Kit.

I installed it on a very small USB drive (265MB) I had lying around and managed to rewrite me a Windows boot record with the tools supplied from the text-based menu. Nice! I also noticed that it has a bunch of disk rescue tools on board like a backup tool, full NTFS support, the Midnight Commander explorer for file recovery and a Windows password reset tool (hackedy-hack). On top of that it also has a virus scanner on board, ways to set up network file shares and good, detailed documentation.

This distro is certainly one that is getting a nice spot on my PC CPR tool belt. Without exploring all the goodness Trinity has to offer I’m sure it’s a huge time saver if you need to help out with a unbootable system or one seriously infected with trojans or virii. You can even use this to set up a headless file share server in no time if you want.

Good stuff.

Photo by lilbambi01, cc-licensed.

how to safely run destructive sql statements

christmas afternoon

This tip is one of those “Why didn’t I think of that before” things when I saw it being used first. You see, sometimes you’re on this production database and you need to run some SQL statements in Microsoft SQL Management Studio. Statements that if you mess them up will end up ruining your customer’s day, and most certainly yours too.
Of course you’ve already taken a backup, but that isn’t perfect. It takes time to restore those and the most recent changes might be lost. The database might also be humongous, making backup & restore operations rather annoying.



You know this! Before you run any statement doing anything destructive on your database, first run the BEGIN TRANSACTION statement. It feels like spring doesn’t it? With fluffy little bunnies hopping around merrily in the green grass and yellow flowers.
Whatever you run next, nothing will actually happen until you run:


If in the meanwhile however that delete statement turns out to act like the Spanish Flue and wipes out half of the precious records stored in your database table, there’s always:


Undo. Restore from last save. You don’t lose a life.
Awesome. More fluffy bunnies.

One thing to keep in mind though. As long as your transaction isn’t committed your statements will be putting locks on rows and perhaps even tables. The longer you keep those, the more chance other people’s queries will have to wait for you to release those locks and might even time out. This is bad. So keep your transaction trickery as short as possible.

For more details on those magical statements, see MSDN.

visual studio 2010 becomes slow after saving on Windows 7

Rust and oil inside "Niles machine tool" (HDR)

Ran into this annoying bugger of a problem with Visual Studio 2010 on Windows 7 where every time I saved a file (any file, no matter how large or small it was) the GUI started reacting extremely slow on me. Menu’s didn’t react, keystrokes didn’t appear, scrolling didn’t work. It acted like a whole bunch of stuff was going on, but nothing really was. After a few minutes or so responses where back to normal, until I saved a file again…

While it was happening CPU usage of devenv.exe was fine (very low). Cleaning the solution didn’t help either, which in some cases fixes odd VS behaviour. In short, I was at a loss. Googling for a solution didn’t really bring up a solid answer, until I found a post that mentioned something about jumplists in Windows 7 and VS 2010 being slow. In that post the antivirus software is blamed but that was not the issue in my case, since the issue only started occurring recently without any changes to my setup.

Using the Systems Internals (great tools there btw if you want to dig deeper into your Windows system) file monitoring tool I noticed that a file in a specific path was sort of hanging things. When I looked up the file it did point to those so-called jumplist thingies again. After clearing these shortcut files, VS started acting like normal again.

So, if you’re having issues with a slow VS 2010 on Windows 7 on saving, try clearing the jumplists like this:

  1. Right-click the Start button
  2. Choose Properties
  3. Uncheck both checkboxes under the Privacy group
  4. Click the Apply button
  5. Re-check both checkboxes
  6. Press OK

If you’re lucky, VS should be running smooth as butter again.

Photo by Morgennebel, cc-licensed.

moving the windows documents and settings profile folder

Connecting to the Interweb Tubes

If you’re running out of disk space on your C-drive on a Windows XP system (which other OS has a C-drive anyway?) you might be thinking of moving your C:\Documents and Settings\youruserprofile to another disk. In my case the profile folder was eating away a good 2.5 GB of space. Moving it saved my ass from having to constantly cleanup that drive and end up in trouble in the long run as slowly but surely updates would fill every last available bit anyway.

There’s a procedure from Microsoft that explains how to do this. In short it goes like this:

  1. Login as Admin
  2. Copy the desired profile folder to another drive, such as D:\Documents and Settings\Bob
  3. Start the registry editor (regedt32.exe) and change all references from the old path to the new one.

This last step is quite a job if you’ve been using the profile for a long time, like myself. I tried this on a test account first and I only had to replace a few references so I thought “Piece of cake! Let’s do this!”. Until I started the same thing for my actual profile and had to replace a gazillion references all over the registry. Bloody hell!

The annoying thing was that even after I replaced all references, some software was still referring to the old profile folder somehow. The bastards! My guess is that some software simply doesn’t expect you to move this folder and has a hard-coded reference built-in. However, there’s a solution for that as well. That solution is also a shortcut to avoid that tedious job of having to change all the registry values, which is bloody boring and prone to errors.

The fix is a tad of Unix magic that also exists for Windows NTFS drives, where you can create a link or virtual folder pointing to a physical folder on another drive. The official name is a “junction point”. For example you can have C:\Document and Settings\Bob point to D:\Documents and Settings\Bob, and not a single piece of software will notice that your files aren’t really on the C drive. Sounds pretty neat huh? This only works with NTFS drives, but any modern version of Windows uses that format by default so that shouldn’t be a problem.

So how do you go about this? Well, it goes like this:

  1. Log in as the administrator user (and not the one you want to move the profile for).
  2. Copy the profile folder to your preferred location on a drive with plenty of free space.
  3. Remove the source profile folder (or rename it, just to be safe).
  4. Create the junction point from the source folder, to the new destination folder, like so:
    linkd.exe "c:\documents and settings\bob" "d:\documents and settings\bob"
  5. Log back in with the moved user. You shouldn’t notice a single problem.

Want more info on that junction point magic? Check out how to create and manipulate NTFS junction points then.

Update: if you’re looking for a similar action on Windows 7 or Vista, check out the mklink command, which is basically the replacement for linkd for the newer Windows versions.

Photo by nickwheeleroz, cc-licensed.