Skip to main content

Senior Web Engineer. Open web / music. Remote DJ. Tall Dutch guy. #3million

micro.blog/sander

svandragt

mixcloud.com/cloudseer

 

Carbon 0.3

It seems today is 0.3 day, as I'm also releasing Carbon 0.3, my hackable performant semi-static blogging system.

This release mainly deals with technical debt as I first started this project 6 years ago as a playground for figuring out how a CMS is written from the ground up. This means there are out of date requirements, references to a Windows platform with Powershell and other such bad examples.

That said the codebase isn't in a terrible state although it will have to change significantly before it's production ready. If you know a bit of PHP then after a short study it can be customised to your needs quite easily.

So, if you're interested you can use it and quickly whip together a documentation or simple blog using only markdown files. It will produce a feed and there's even a half baked cli application and static site generation that I have to review before I can recommend it in honest.

carbon 0.3 theme

Have fun hacking!

 

Automatic crash reporting using FogBugz for PowerShell

This morning I integrated our PowerShell processes into FogBugz by writing a small module that submits occurrences of all errors to BugzScout. You might want to do something similar so I did this write-up.

Broadly it works similar to BugzScoutLogWriter that I developed previously for integration with SilverStripe CMS. In this case however, we need to do the following things:

  1. Set the script to stop on all errors so they can be trapped instead of ending the execution of the script.
  2. Capture the error details and submit them to FogBugz
  3. Have an error occur. ;)

I've published the code in a Gist for you a have a look. I include the function in every script I use.

 

Tweet: #powershell tip: $ContentsWithLinebreaks = (Get-Co...

tip: $ContentsWithLinebreaks = (Get-Content $FilePath) -join "`n"

 

When Get-ADUser does not return the complete user

When writing a Powershell script that checks for changes to Active Directory users, you may find that all users change every time you run the script. One explanation for seeing this behaviour is because Get-ADUser does not return all the fields. A field that is not returned can never be equal to a string value.

For example, let's consider the following code:

$csv_file  = "users.csv"
Import-Csv $csv_file | ForEach-Object { 
    $username = $_.USERNAME
    $ad_user = (Get-ADUser -filter {sAMAccountName -eq $username})
    if (!$ad_user) {
        # create account, it does not exist
    } 
    else {
        $filter_accountchanged = { $ad_user.DisplayName -cne $displayname }         
        if ($ad_user | Where $filter_accountchanged) {
            # update existing accounts with changes 
        }
        else {
            # account exists and has not changed
        }
    }
}

You will find that all existing accounts come up as having changed. This is because $user.DisplayName is not returned by Get-ADUser.

The issue is resolved by asking Get-ADUser to return all properties:

$ad_user = (Get-ADUser -filter {sAMAccountName -eq $username} -Properties * )

Now all properties are returned, and the "account change" filter works as expected.

 

Carbon Powershell support is here!

I have been working with Carbon over the last weeks and one thing I noticed was that having to navigate through the admin menu repeatedly was getting a bit long in the tooth. Sure, for the occasional admin task it's useful to have the admin close to the site itself.

After adding deployment through powershell it became clear that switching between admin and commandline is not ideal either. So I decided to implement all administration throughu the powershell script.

With 0.2.3 you can add the following parameters to the script:

  • login: login to admin
  • draft: create draft
  • generate: generate static site
  • deploy: deploy to live
  • clear_cache: empty cache

The script will also tell you the correct syntax if you get it wrong. Happy carbonating!

 

Carbon 0.2.3 Released

I've released another version of Carbon, the framework powering this website. It's really a refinement and bugfix release, with the following changes:

  • config: Admin password now needs to be manually enabled
  • cache: Correctly generate htaccess
  • deployment: only replace hostnames in text files
  • cache: only write cache when caching is enabled.
  • theme: remove older articles link (non functional)
  • deployment: new feature - replace hostname from a to b before deploying cached site

Releases are available via github by clicking on tags.

Screencast

To celebrate the new release, I've also recorded another screencast (list of screencasts). In Screencast #4, we create a new post using the admin interface; use the generate site feature to create a full static cache; and finally run the powershell deployment script to deploy to my host over sftp.

All in under 2 minutes!

 

Getting started with Powershell

PowerShell is a complete replacement for any of Microsoft's DOS or Windows command line interpreters. It is a full fledged object oriented system administration scripting language. With PowerShell knowledge you would run circles around any sysadmin that works predominantly from through the GUI, as well as be able to get Windows to do things that you just can't do through a GUI alone.

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/index.mspx