Amazon has a nice section in their CodeDeploy user guide, describing how CodeDeploy can integrate with their Elastic Loadbalancer product.
If you rely on your loadbalancers health check to detect that an instance being deployed to has stopped responding, you will unavoidably end up sending some user requests to the failed instance before it's removed from the loadbalancer. By letting CodeDeploy interact with the ELB you can gracefully deregister the instance from the loadbalancer before the deployment and then reregister it again after, with all your traffic being send to healthy instances meanwhile.
Amazon provides sample shell code for Linux, but as I wanted to do the same with Windows instances I re-implemented the scripts in PowerShell
Since I didn't need the Application Loadbalancer or Autoscaling functionality, those are missing from the PowerShell version. There is a short introduction to usage in the README file on github, but else refer to the Linux version as the ideas and requirements are the same.
Update@2017-18-01: ALB support has been added
I also became a bit more familiar with powershell in the meantime, so the implementation is a bit nicer than the original ELB version.