Wednesday, October 24, 2012

WARNING: The generated type defines no public methods or properties

I received the following warning while using the Add-Type CmdLet in PowerShell:
WARNING: The generated type defines no public methods or properties.
Since I was aware that this was the case, I suppressed the warning using the following parameter to Add-Type:
Add-Type -WarningAction SilentlyContinue ...

Monday, October 22, 2012

Text bootloader in Windows 8

Windows 8 installs a new, quite nice looking, graphical bootloader. Unfortunately, this bling comes with a fairly serious drawback - Windows 8 needs to boot before the bootloader is displayed on the screen, which can take 20 seconds or so, and then if you have the audacity to want to boot into another operating system, the machine will be rebooted, forcing you to endure another BIOS POST sequence.

The workaround is to enable the text based bootloader using bcdedit (note that the backticks (`) are required in PowerShell to escape the braces):
bcdedit /set `{current`} bootmenupolicy legacy
To switch back to the graphical bootloader, run the following command:
bcdedit /set `{current`} bootmenupolicy standard
You'll need to run these PowerShell commands as an administrator.

Friday, October 19, 2012

After recently importing a Subversion repository into Git, along with the associated .gitignore file, I noticed that git status was performing poorly. The solution was to split the monolithic .gitignore file in the root folder into multiple .gitignore files spread throughout the repository.

I wrote the following PowerShell script to do so:
$content = type .gitignore | % { $_.Trim() } | ? { $_.StartsWith('/') } | % { $_.SubString(1) }
$content | % {
    $folder = split-path -Parent $_    
    if($folder.length -gt 0) {
        if(-not (test-path $folder)) {
            md $folder | Out-Null
        }
        $pattern = split-path -Leaf $_
        $newPattern = '/' + $pattern
        $ignoreFile = "$folder\.gitignore"
        $exists = $false
        if((test-path $ignoreFile ) -and (type $ignore) -notcontains $newPattern) {
            $exists = $true
        }
        if(!$exists) {
            Add-Content -Force -Path $ignoreFile $newPattern
        }
    }
}

Friday, October 12, 2012

Adding credentials to the Windows credential store from the command line

Service users often do not have permission to start GUI applications, so the following tool can be used to store credentials that can be used to access a server, for example to copy a backup onto a remote file share.

cmdkey.exe

The syntax to add credentials to the store is:

cmdkey /add:targetname /user:username /pass

Monday, October 8, 2012

Git Cookbook

This page lists some useful commands that I use with Git:
  • Show all branches that contain a commit. Useful to see which branches a topic branch has been merged into.
    • git branch --all --contains commit
  • Show which branches have not been merged into the current or specified branch.
    • git branch --all --no-merge [branch]
  • Pretty-print history tree
    • git log --oneline --graph --decorate --all
  • List all changes that will be sent with the next push
    • git log --branches --not --remotes
  • Update from remote
    • git fetch
    • git rebase -p
  • Get name of remote tracking branch for the current branch
    • git branch -vv | ? { $_ -match '^\*' } | % { $_ -match '\[([^:]+)' | Out-Null; $Matches[1] }
  • Get the most recently modified topic branch
    •  git for-each-ref --sort=-committerdate --format='%(refname)' refs/remotes/origin/topic | select -first 1