Skip to content

Instantly share code, notes, and snippets.

@stratalux
Created April 11, 2011 18:07
Show Gist options
  • Save stratalux/913958 to your computer and use it in GitHub Desktop.
Save stratalux/913958 to your computer and use it in GitHub Desktop.
Rename Windows Node and Reboot with Chef-Solo on RightScale Platform
#
# 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