20 Apr 2012 @ 5:26 PM 

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 Glimlach

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
}

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 23 Apr 2012 @ 06:12 AM

EmailPermalink
Tags


  • Andrew Barnes.

    Nice post. I’d keep it 100% powershell by using the Restart-Computer cmdlet. http://technet.microsoft.com/en-us/library/hh849837.aspx

  • http://www.jeffwouters.nl Jeff Wouters

    Hi Andrew,
    Thanks. I agree, native PoSH is better. The post was written before PS 3 was RTM, that’s why I didn’t. But good of you to mention it, thanks!
    Jeff


 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 251
  • Comments » 430
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.