Posts

Bulk Add Active Directory Computers

Occasionally, we order a large number (30+) computers at work and it a lot easier to bulk create the computers than manually move them and set their description (it also makes it easier to pass out software via GPO) after they have been joined to the domain. To do this I have created the following PowerShell one liner:

Import-module ActiveDirectory
Import-Csv "BulkComputers.csv" | foreach-object {New-ADComputer -Name $_.Name -SamAccountName $_.Name -Path $_.OU -Enabled $true -Description $_.Description}

It requires a CSV file with the Name of the computer, the OU the computer should be created in and the Description. It works awesome and takes a job that usually takes 15+ minutes to less than 5.

Drainstop in NLB

I have been testing HA solutions at work for our SharePoint deployment and we are looking at using Microsoft's Network Load Balancer (NLB) technology that's built into Windows Server.  One of the options I saw when I clicked on a node I saw an option that said Drainstop and of course I found what I was looking for in TechNet:

When you use the stop command, either through Network Load Balancing Manager or the command prompt, any client connections already in progress are interrupted. To avoid interrupting active connections, consider using the drainstop cluster-control command, which allows the host to continue servicing active connections, but disables all new traffic to that host. For more information, see "Disable new traffic handling and stop Network Load Balancing" in Related Topics.

http://technet.microsoft.com/en-us/library/cc781186(WS.10).aspx

I looks like this is the idea way to stop the NLB cluster from routing information to a host that I will need to take offline for maintenance.

Get The Count of the Number of Users in an AD Group

I was challenged at work today to determine  the number of users in an Active Directory group. I figured the best way was to break out PowerShell and see what I could find (I'm sorry but I'm learning PowerShell so things are going to be very PowerShell centered for a while :-)). I found that in the ActiveDirectory PowerShell module (see http://www.mikepfeiffer.net/2010/01/how-to-install-the-active-directory-module-for-windows-powershell/ for instructions on how to install this) the Get-ADUser cmdlet works really well for running basic searches in AD.

The first step is to import the module:

Import-Module ActiveDirectory

Then you can run a search on the user information you want for example this returns the count of all users in a group:

(get-aduser -filter {memberof -recursivematch "CN=Group,OU=Users,DC=contoso,DC=local"}).count

This returns the count of all group members who have an expiration date:

(get-aduser -properties AccountExpirationDate -filter {memberof -recursivematch "CN=Group,OU=Users,DC=contoso,DC=local"} | where {$_.AccountExpirationDate -ne $null}).count

The cool things about the get-aduser cmdlet is that it automatically pulls common fields (username, surname, etc.) but by adding items to the -property field it will return additional items. If there are other searches you find useful please add them to the comments below.

Accepting Credit Cards Online

Nettuts+ has an interesting and detailed article on how to use stripe to accept credit cards on your website. After using authorize.net it's nice to see a cheaper up front option.

http://net.tutsplus.com/tutorials/other/so-you-want-to-accept-credit-cards-online/

Trick for Handling Checkboxes

One of the downsides to using checkboxes in HTML is the fact that if you don’t have the checkbox checked when the form is submitted it’s value doesn’t get submitted to the server so no value is sent for that form element.

However, if you put a hidden element before the checkbox the checkbox value will override the hidden element’s value if the checkbox is checked:
[sourcecode language='html']


[/sourcecode]

try.github.com

github.com has a really cool site that allows you learn the basics of git quickly:

http://try.github.com/

Access view from inside a view helper

Ready to have your mind blown? I wanted to access a view helper from inside another view helper and it doesn't allow it by default. It turns out you have to add the function setView() to your view helper and then you will have access to the view helper. The trick (in PHP 5.3 at least) is to make sure you include the Zend_View_Interface before you name the parameter or it won't work (you'll get a nasty error message).

class Zend_View_Helper_DisplaySomeData extends Zend_View_Helper_Abstract{ 
     protected $_view; 
     public function setView(Zend_View_Interface $view){
        $this->_view = $view; 
     } 

     public function DisplaySomeData($data){ 
        return $this->_view->SomeOtherViewHelper($data) . ' some text'; 
     } 
}

Feature Branching vs Code Toggling

A couple months ago I found an article that explained how one company uses git branches to manage their software deployment process.  They use a branch off their development branch for each feature and then when the feature was done they merged it back into their development branch.  During my last project I used something similar to this (mostly so I could fix bugs as they were reported) but the feature branches usually only lasted a few hours or at most a couple days.

In the comments, someone linked to the following YouTube video which explains why it's a bad idea to do this in the long term.

The video isn't super long but the TL;DR version of it is that when you perform a merge there is a cost to doing the merge.  The longer you go between merges the more it costs to merge two branches together because of how far they diverge (makes sense when you think about it).  In the video they suggest practicing Continuous Integration and merging your code back to the mainline branch daily.  The suggestion from the video is to instead use feature/code toggling or branching by abstraction to get the same feature.  That way new features are only launched when you're ready for them.  It turns on that lots of people use this approach even Flickr. I really liked the blog post Experience Report: Feature Toggling by Sarah Taraporewalla explaining her experience with feature toggling.

The basic idea behind code toggling is very simple:

  1. Create a flag in your code for a new feature/change.
  2. As you add the new feature you wrap the new code in an if block so it's inaccessible if the feature isn't turned on.
  3. Turn the feature on in testing, production, x % of your servers.
  4. See if anything breaks.  If it does turn the feature back off.
  5. After the feature has been deployed for a long time (you'll have to determine what's best for your company) go back through and remove the toggle point and the old code.

It seems simple but really powerful.  I'm going to start looking into implementing it on one of my upcoming projects so hopefully there will be a future article on how that worked out.

Principles of Agile Development

Nettuts+ has an interesting article on the Principals of Agile Development.  I think this might be the first time I've actually read a description of what agile development is so I think it's worth a read:

http://net.tutsplus.com/articles/general/the-principles-of-agile-development/

Oddity With fgetcsv

PHP has a really cool function called fgetcsv which provides a really simple way to read CSV data.  I used it in a script recently and it worked perfectly with my test data and then someone with with a Mac ran their data through it and it failed horribly.

It turns out you have to set the auto_detect_line_endings option to true BEFORE the fopen function for it to work.  If the call to ini_set occurs after the fopen it doesn't work correctly.

RSS

Join Our Mailing List!

View previous campaigns.

Top Posts

  1. Working With Soft Deletes in Laravel (By Example)
  2. Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
  3. Upgrading to Laravel 8.x
  4. Get The Count of the Number of Users in an AD Group
  5. Multiple Vagrant VMs in One Vagrantfile
  6. Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
  7. Changing the Directory Vagrant Stores the VMs In
  8. Accepting Android SDK Licenses From The OSX Command Line
  9. Fixing the 'Target class [config] does not exist' Error
  10. Using Rectangle to Manage MacOS Windows

subscribe via RSS

All content copyright This Programming Thing 2012 - 2021
Blogging about PHP, MySQL, Zend Framework, MySQL, Server Administration and Programming in general