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

Wednesday, June 20, 2012

Get status of all Git repositories using PowerShell

The following PowerShell one-liner will get the status of all Git repositories:
dir -r -i .git -fo | % { pushd $_.fullname; cd ..; write-host -fore yellow (get-location).Path; git status; popd }
Note that this will not work for bare repositories.

Wednesday, June 6, 2012

Installing (and booting) Windows 8 on a VHD

Windows 8 (and Server 2012) greatly simplifies installing Windows 7 / Windows Server 2008 R2 / Windows 8 / Windows Server 2012 to a VHD or VHDX for booting without having to mess around with partitions. Convert-WindowsImage.ps1 is a fantastic tool that you can run from Windows 8 or Server 2012 to install a new operating system without rebooting your machine. To install Windows 8 Release Preview on a VHDX, I did the following:

  1. Download and unblock the PowerShell script Convert-WindowsImage.ps1. I couldn't find the unblock checkbox on the file properties dialog, so I used the Sysinternals streams.exe utility to remove the block:
    streams -d Convert-WindowsImage.ps1
  2. I then mounted the Windows 8 ISO image by double clicking on it in Explorer, taking advantage of the belated ISO mounting feature. In my case, it mounted to E:.
  3. Next, I ran Convert-WindowsImage.ps1 with the following command line:
    .\Convert-WindowsImage.ps1 -SourcePath E:\sources\install.wim -VHDFormat VHD -SizeBytes 50GB -VHDPath Windows8RP.vhd -VHDType Fixed -Edition Professional
  4. Mount the VHDX using diskmgmt.msc. I tried using Mount-DiskImage, but kept running into the following error: "Mount-DiskImage : One or more parameter values passed to the method were invalid." My drive was mounted as F:
  5. Run the following command to add your new VHD to the boot menu:
    bcdboot F:\Windows
  6. Reboot and select the new O/S in the boot menu.