I am new to powershell and I am trying to rename my Windows 7 laptop using
powershell. I have the following script and it's not working. Does anyone
know where I am going wrong? I wish to rename the computer using the
SerialNumber from W32_Baseboard.
Function Rename-ComputerName ([string]$NewComputerName){
$ComputerName = Get-WmiObject -Class Win32_BaseBoard | select SerialNumber
$ComputerInfo = Get-WmiObject -Class Win32_computersystem
$ComputerInfo.rename("$ComputerName")
}
Restart-Computer
Thanks in advance.
Regards,
Mark
don't have a change to try it, however can you try following?
Function Rename-ComputerName ([string]$NewComputerName){
[String]$ComputerName = Get-WmiObject -Class Win32_BaseBoard | select
SerialNumber
$ComputerInfo = Get-WmiObject -Class Win32_computersystem
$ComputerInfo.rename("$ComputerName")
}
Restart-Computer
Martin
"Mark" <Ma...@discussions.microsoft.com> wrote in message
news:B19AA1E0-409C-4963...@microsoft.com...
PS> Get-WmiObject -Class Win32_BaseBoard
Manufacturer : Wistron
Model :
Name : Base Board
SerialNumber :
SKU :
Product : 303C
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
Try going after - Win32_BIOS | Select SerialNumber
Ant
1) parameter $NewComputerName is used anywhere inside function
Rename-ComputerName
2) a call to function Rename-ComputerName with a specific value for parameter
$NewComputerName is made before the Restart-Computer command is executed
- Larry