• Looks like you are missing a parameter in the DetachDatabase syntax.

    See this: http://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.detachdatabase.aspx

    You need to add a Boolean for the update statistics parameter. Assuming you don't want to do this, it would look like

    $server.DetachDatabase("databasename", FALSE)

    - Tony Sweet