Clear writing

The best way to write a clear blog post is to paste your draft into a text-to-speech engine such as tts-api.com and listen to the output. If you can’t easily understand what is said then that will most likely indicate problems with your sentence structure.

November 13, 2012 at 4:48 PM in Web

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.

November 13, 2012 at 4:56 PM in ActiveDirectory

SilverStripe Gists

I’ve released the following data extensions (might pack them up as modules):

  • HiddenFields DataExtension: Takes form fields specified through $hidden_fields and hides them from edit form. View code
  • Description DataExtension: Specify a $db_descriptions array to DataObjects to attach formfield descriptions. View code

November 12, 2012 at 9:07 AM in SilverStripe

Windows 8 a catastrophe for Games?

Interesting article by Tom Phillips interviewing developers about Windows 8 and it’s closed Windows Store, with this gem of a quote from Introversions’ Chris Delay:

“I really don’t want to see the PC becoming a closed platform. Microsoft is not a company that’s able to benignly oversee that process. They will f*** it up. We’ll all be doing Kinect support and 16 language versions, we’ll all be supporting a Microsoft Office plug-in. It’s my own worst nightmare.

[…] “The PC continues to be as relevant as it was ten years ago, despite consoles coming and going, because it is an open platform. If that changed it would be terrible.”

It’s interesting times for the gaming industry, indeed.

November 8, 2012 at 2:05 PM in Games, Windows

OptimisticLocking SilverStripe Module Release

Some of you might be interested in my first ss module: silverstripe-optimisticlocking

This is a very simple module that prevents your site users from losing data. It works by by blocking the save process if the record changed since it was retrieved, preventing accidental overwrites. (user1 starts editing, user 2 starts editing, user1 saves, now user2 can’t overwrite user1’s changes). By default, Silverstripe lets you lose data by overwriting the record on save.

You might know that Pages benefit from versioning (so you can restore to a previous version), however by default DataObjects don’t have versioning enabled so this module will come in handy then (AFAIK it’s not trivial to enable either).

If feedback is good, I will try to add it to the SilverStripe modules list.

November 8, 2012 at 1:04 PM in SilverStripe

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!

November 6, 2012 at 3:10 PM in Carbon, Games

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!

November 6, 2012 at 9:23 AM in Carbon