Thursday, February 24, 2011

Creating a basic PowerShell script module

It is convenient to put frequently used functions into a PowerShell module. To do this, simply go to (after creating it, if need be) a folder called Documents\WindowsPowerShell\Modules (for the paths you can use, run this command: echo $env:PSModulePath).

Create a folder by the name of the module you want to create e.g. Utilities. Within that folder, create a .psm1 file by the same name as that folder e.g. Utilities.psm1. Any function you create in the .psm1 file will be imported when you import the module.

Additional information:
  • gmo -ListAvailable should list your new module, along with others installed in your system.
  • ipmo Utilities will load your module (if it is called Utilities).
  • rmo Utilities will unload your module (if it is called Utilities).
  • gcm -Module Utilities will list all the functions exported by your module once it is loaded (if it is called Utilities).
  • Export-ModuleMember allows you to choose which functions you export from your module.

PowerShell script to find and open solution (.sln) files

Finding and opening Visual Studio solutions in multiple projects and branches can be painful at times. This simple script may help:

param([int]$OpenId)

$it = 0
$sln = dir -Filter *.sln -Recurse | 
    sort FullName |
    % { New-Object psobject -Property @{ Id = ++$it; Name = $_.Name; FullName = resolve-path -relative $_.FullName } }

if($OpenId)
{
    if($OpenId -lt 0 -or $OpenId -gt $sln.length)
    {
        throw "Invalid Id."
    }

    & $sln[$OpenId - 1].FullName
}
else
{
    $sln
}

Sunday, February 20, 2011

Copying video from the JVC GR-D850AA using firewire on Linux

It seems that our JVC GR-D850A works on Vista, but not on Windows 7, so I thought this might be something that Linux could solve for me.

I started up Kino on my Linux Mint Debian Edition partition, and was able to fast forward and rewind the tape, but I only saw a black screen when playing. CLI application dvgrab to the rescue.

To copy the video and split into timestamped files, I ran this command:

dvgrab -buffers 1000 -rewind -autosplit -format avi -timestamp video

I needed the buffering because I was streaming over a network.

Note that dv1 format seems to crash mplayer. Another useful command is this, which streams the video directly into mplayer:

dvgrab - | mplayer -

To control the tape, you can use the dvcont command:
dvcont stop
dvcont rewind
dvcont status

Using mencoder and find, the following command will convert a folder of AVI files into XVID format, saving them into a subdirectory called small:

find . -name "*.avi" -type f -exec mencoder {} -ovc xvid -oac mp3lame -xvidencopts fixed_quant=3 -o small/{} \;

Wednesday, February 9, 2011

Getting TFS Power Tools 2010 working on a 64 bit machine

If you install the Team Foundation Server Power Tools on x64 Windows, the TFS cmdlets will only be accessible in x86 PowerShell, not x64. This is because the installer is x86 and installs the required registry entries to the x86 registry. We can copy those entries by running the following command as an administrator from the 64 bit console:

copy HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell -r

Then, to load the TFS Power Tools snapin (unfortunately, not a module), run:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell