• Useful PowerShell snippets (part 1)

    Some things I’m finding useful:

    Processes running on a machine

    Get-WmiObject Win32_Process -ComputerName mymachine | Select { $_.Name }

    Currently logged in user on a machine

    Get-WmiObject Win32_ComputerSystem -ComputerName MyMachine | Select { $_.UserName }

    Does a machine have .NET 3.5 SP1 installed

    function Get-Net35SP1([string] $machineName) {     $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $machineName)     $regKey= $reg.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" )     if ($regKey -ne $null) {         Write-Output $regKey.GetValue("SP", 0)         $regKey.Close()     } else {         Write-Output "Doesn't have .NET 3.5"     }     $reg.Close() }

  • Log4net’s SmtpAppender with multiple email addresses

    Log4net is a popular logging framework, and amongst the various logging “appenders” it includes one for sending emails – the SmtpAppender. The documentation for the SmtpAppender’s To property says it contains a semicolon-delimited list of email addresses.

    However if you try to do that, you won’t see any emails being sent. Add the following to your app.config file to enable log4net’s debug logging:


    <add key\="log4net.Internal.Debug" value\="true" />



    <trace autoflush=“true”>


    <add name\="textWriterTraceListener"
     initializeData\="C:\\\\tmp\\\\log4net.txt" />



    You’ll then see this internal error message in the log4net.txt file:

    System.FormatException: The specified string is not in the form required for an e-mail address. at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName) at System.Net.Mail.MailAddressCollection.ParseValue(String addresses) at log4net.Appender.SmtpAppender.SendEmail(String messageBody) at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] events)

    This shows that the SmtpAppender is leveraging the .NET Framework’s System.Net.Mail.MailAddressCollection class. The ParseValue method is not public, but Add(string) is, and if you scroll down to the remarks, you’ll see the following text:

    If multiple e-mail addresses separated with a semicolon character (“;”) are passed in the addresses parameter. a FormatException exception is raised.

    So it turns out log4net’s documentation is misleading, or at least out of date. Change your email addresses to use the comma and everything comes good again.

  • Drought breaks..

    I’m pleased to report that it appears the biscuit drought has broken. We’re seeing good falls of assorted creams as well as the good old family assorted again.

    That is a relief!

    One of the nice things about my current workplace – they provide tea, coffee, Milo (but not Bonox!) and usually once a week if you’re lucky you’ll find some bickies in the kitchen, presumably left by the biscuit fairy.