Created
April 11, 2011 18:58
-
-
Save stratalux/914060 to your computer and use it in GitHub Desktop.
Join Windows Node to Active Directory domain with Chef-Solo on Rightscale platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: development | |
# Recipe:: renameComputer | |
# | |
# Copyright 2011, YOUR_COMPANY_NAME | |
# | |
# All rights reserved - Do Not Redistribute | |
# | |
powershell "Join Active Directory Domain" do | |
parameters({'DOMAIN_ADMIN' => @node[:development][:DOMAIN_ADMIN]}) | |
parameters({'DOMAIN' => @node[:development][:DOMAIN]}) | |
parameters({'DOMAIN_ADMIN_PASSWORD' => @node[:development][:DOMAIN_ADMIN_PASSWORD]}) | |
powershell_script = <<'POWERSHELL_SCRIPT' | |
$username = "$env:DOMAIN_ADMIN"; | |
$domain = "$env:DOMAIN"; | |
$password = "$env:DOMAIN_ADMIN_PASSWORD"; | |
$message=""; | |
function addComputer | |
{ | |
param([string]$username, [string]$password, [string]$domain) | |
try | |
{ | |
add-computer -domain $domain -credential (New-Object System.Management.Automation.PSCredential ($username, (ConvertTo-SecureString $password -AsPlainText -Force))) -passthru -verbose | |
} | |
catch | |
{ | |
$message += "An error occcured while joining computer to domain." + "`n`rError: $_"; | |
write-host "Error" $message | |
} | |
} | |
addComputer $username $password $domain | |
Restart-Computer | |
POWERSHELL_SCRIPT | |
source(powershell_script) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment