Blocking Websites with the Hosts File


#  path: /etc/hosts
#  ls -1alt /etc/hosts*
#  head -20 /etc/hosts

#  path: C:\windows\system32\drivers\etc\hosts
#  gci C:\windows\system32\drivers\etc\hosts* -force
#  gc C:\windows\system32\drivers\etc\hosts | select -first 20 spam.com f.ads.com www.msn.com


Checkout One File from SVN

A Slik SVN/PowerShell workaround for the SVN missing feature - checking out just a few select files instead of the entire folder.
$svnFolder = 'https://dev.co.com/svn/project1'
$workingFolder = 'c:\temp\svn'
$file = 'foo.cs'

#checkout just the folder, checkout depth "only this item"
&svn checkout $svnFolder $workingFolder --depth=empty

#method 1: cd to working folder, update using file name
cd $workingFolder
&svn update $file

#method 2: update using file full path name
$file = join-path $workingFolder $file
&svn update $file


PowerShell Registry Script

Four variations for reading registry keys.
HKLM and HKCU are PowerShell drives for HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER registry hives.

Windows startup entries.
getRegistryV1 hklm:\software\microsoft\windows\currentversion\run
getRegistryV1 hkcu:\software\microsoft\windows\currentversion\run
function getRegistryV1($key)
  $key = get-item $key
  $values = get-itemProperty $key.psPath  #gp alias for get-itemProperty

function getRegistryV2($key)
  $key = get-item $key
  $values = get-itemProperty $key.psPath
  foreach ($value in $key.property)
    "$value = $($values.$value)"  #subexpression $()

function getRegistryV3($key)
  $key = get-item $key
  $maxKeyNameLen = ($key.property | %{$_.length} | measure -max).maximum
  $values = get-itemProperty $key.psPath
  foreach ($value in $key.property)
    "{0,-$maxKeyNameLen} = {1}" -f $value, $values.$value  #format left-aligned width

function getRegistryV4($key)
  $key = get-item $key
  $maxKeyNameLen = ($key.property | %{$_.length} | measure -max).maximum
  $values = get-itemProperty $key.psPath
  $key.property | %{"{0,-$maxKeyNameLen} = {1}" -f $_, $values.$_}  #format left-aligned width


ASP.NET 4/IIS ManagedPipelineHandler Error

ASP.NET 4 error on Windows 7/IIS 7.5
HTTP Error 500.21 - Internal Server Error
Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list.

To fix, install ASP.NET 4 using the .NET 4 ASP.NET IIS Registration Tool.
See documentation for differences between the -i and -ir options.
c:\windows\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe -i


Testing String Format in PowerShell

'{0:x2}' -f 10
[string]::format('{0:x2}', 10)

Testing String Format in F# Interactive

printf "%02x" 10;;
System.String.Format("{0:x2}", 10);;
open System;;
String.Format("{0:x2}", 10);;
val it : string = "0a"