This is something I took from one of my larger deployment scripts and found it to be very useful and reusable.
Just to give you a use case: In my situation the parameter $NewComputerName is calculated based on the device type (server, laptop or desktop), the IP range and a random number taken from a text file located on a file share.
I hope you find it useful ![]()
Function Rename-Computer ($NewComputerName)
{
# Get the current credential.
$credential = Get-Credential# Get the current computer name
$OldComputerName = $Env:ComputerName# Change the computer name.
Get-WmiObject Win32_ComputerSystem -ComputerName $OldComputerName -Authentication 6 | ForEach-Object {$_.Rename($NewComputerName,$credential.GetNetworkCredential().Password,$credential.Username)}# Reboot the computer to let the change take affect.
Shutdown.exe -r –t 7
}

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 