Created
April 11, 2011 18:07
-
-
Save stratalux/913958 to your computer and use it in GitHub Desktop.
Rename Windows Node and Reboot 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 "Rename Windows Computer" do | |
parameters({'HOST_NAME' => @node[:development][:HOST_NAME]}) | |
powershell_script = <<'POWERSHELL_SCRIPT' | |
$newName = "$env:HOST_NAME" | |
$message="" | |
function RenameComputer([string]$NewName) | |
{ | |
try | |
{ | |
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem | |
$ComputerInfo.rename($NewName) | |
} | |
catch | |
{ | |
$message += "An error occcured while editing the registry." + "`n`rError: $_"; | |
} | |
} | |
RenameComputer($newName) | |
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