All posts by Torleif

YouTube: Play all uploads of a user

Note to self: To play all uploads of a user, start playing one of them, then add &list=UL to the URL. For example:

The playlist might look a bit weird at first, but that’s because

  • It plays from oldest to newest
  • The current playing video “tries” to be in the middle of the list
  • The list only displays x videos before and y videos after the current one, so if the user has a thousand videos, you’ll only see a handful of them in the playlist, but it does play through them all.

Of course YouTube should just have a “play all videos of this user” button, but can’t find one at the moment…

PowerShell: Read hashtable from a file

Had a file with the following kind of data.

Wanted to read this in as a hashtable so that I could use it for lookup in a script. Tried doing the following, but ended up with an array of hashtables instead of one hashtable. This is because Get-Content by default actually gives you an array of lines, which are then piped into ConvertFrom-StringData one by one.

PS> Get-Content .\hostnames.txt | ConvertFrom-StringData
PS> $names.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

PS> $names[0].GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Hashtable                                System.Object

Turns out it was easy to fix by adding the -raw parameter.

PS> $names = Get-Content -raw .\hostnames.txt | ConvertFrom-StringData
PS> $names.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Hashtable                                System.Object

PS> $names['']

PowerShell: Parse, sort, filter and add to a CSV

Made an export from Splunk containing all IP addresses who had called a method on a companies ESB servers. This gave me a large CSV with two columns, Method and IP, which I then needed to filter to remove duplicate rows. Additionally I wanted to try a reverse lookup of the address to identify what system in our environment was actually doing the call us.

Import-Csv .\requests.csv |
sort Method,IP -Unique |
select *,@{Name="Host";Expression={[Net.Dns]::GetHostEntry($_.IP).HostName}}
Export-Csv .\requests-filtered.csv

Most lines should be self-explanatory, but the neat bit is the select statement. I use the * to select all existing properties, and then I use a nutty syntax I learned today to add a calculated property.

Pretty neat. Worked great, with the exception that every IP was resolvable, but’s the fault of the DNS server at the company… :)

Change network profile name and type in Windows 8

The Network and Sharing Center in Windows 8 is kind of useless in many ways. There is for example no way to change the name, so you might be stuck with a dumb “Network 3″ identity. There’s also no way to change between the Public and Private types if you want to change what you selected when you initially connected to the network.

So, on your own responsibility, here’s where to find those profiles in the Registry Editor.

  • HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\Windows NT \CurrentVersion \NetworkList \Profiles

Of particular note is the ProfileName and the Category. The last one can have the following values:





Use WinMerge for comparing archives with TortoiseSVN

I really like the Diff Viewer that comes with TortoiseSVN, but from what I can gather it doesn’t seem to support anything but text files, which is fair enough, but I need to compare archives as well. Zip and Jar files in particular.

WinMerge supports that, and can be integrated with TortoiseSVN very easily right through its installer. But I prefer the diff viewer that comes with TortoiseSVN and the archive diff isn’t recursive by default, so I decided to set it up manually.

  1. Install WinMerge
    (without the automagic TortoiseSVN integration)

  2. Install the WinMerge 7-zip plugin for archive support
    (I couldn’t get the shared install to work, so had to use the application specific one)

  3. Open TortoiseSVN Settings, Diff Viewer, Advanced
  4. Add rows with extension set to .zip, .jar and whatever archives you want WinMerge to handle and set external program to the following:
    C:\Program Files (x86)\WinMerge\WinMergeU.exe /r /x /e /u /dl %bname /dr %yname %base %mine

If I now for example ask TortoiseSVN for a Diff with previous version of a jar file, I get WinMerge with a recursive comparison of the archive contents. I also recommend that you deselect Show Identical Items under View.

BAT: Change working directory to directory of script

Sometimes you want a batch file to always run with the directory of the script as the working directory. Not whatever directory you ran it from.

@echo off
pushd %~dp0
do stuff

Here pushd changes the directory to %~dp0, which is the directory of the running batch script. popd returns to whatever it was when the script started running. Not sure if the last step is necessary, but there you go anyways :)

PowerShell: Write stuff to an XML file

Needed to recursively list all the files of a certain type and save them as an XML file. Turns out this was pretty easy using PowerShell.

# Make a regular .Net XmlTextWriter
$output = "processes.xml";
$xml = New-Object System.Xml.XmlTextWriter($output, $Null);
$xml.Formatting = "Indented"
$xml.IndentChar = " ";
$xml.Indentation = "1";

# Start writing

# Do the listing and keep outputting XML
Get-ChildItem .. -Recurse -include *.esbp |
foreach {
    $name = $_.BaseName;
    $path = Resolve-Path $_ -relative;

    $xml.WriteAttributeString("id", $name);

# Close the writer, which also closes the root element and document for us

Easy peasy!