\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!\nUse a descriptive subject. Don't say \"Need help\" or \"PowerShell Help\", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…\n <\/blockquote>\n<\/aside>\n <\/p>","upvoteCount":1,"datePublished":"2019-09-17T20:13:58.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"\n\n
<\/div>\n
briansorrells:<\/div>\n
\nRename-Computer : Computer name @{Name=DESKTOP-ACIB4OI} cannot be resolved with the \nexception: One or more errors occurred…<\/p>\n<\/blockquote>\n<\/aside>\n
you have to expand that.<\/p>\n
$ServiceTAG = (Get-WmiObject Win32_BIOS).serialnumber\n$OLDNAME = (Get-WmiObject win32_COMPUTERSYSTEM).Name\nRename-Computer -ComputerName $OLDNAME -NewName $ServiceTAG -force -Restart\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2019-09-17T20:14:53.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"If you run that PS to get the service tag, you’ll find you get a header string “serialnumber”, a carriage return, a dotted line, another carriage return, and finally the actual service tag. I don’t think you want all that as the new machine name. You need to parse out just the service tag itself.<\/p>\n
$ServiceTAG = Get-WmiObject Win32_BIOS | Select-Object -ExpandProperty serialnumber\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-09-17T20:16:17.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/4","author":{"@type":"Person","name":"dzee","url":"https://community.spiceworks.com/u/dzee"}},{"@type":"Answer","text":"\n\n
<\/div>\n
DZee:<\/div>\n
\nIf you run that PS to get the service tag, you’ll find you get a header string “serialnumber”, a carriage return, a dotted line, another carriage return, and finally the actual service tag. I don’t think you want all that as the new machine name. You need to parse out just the service tag itself.<\/p>\n<\/blockquote>\n<\/aside>\n
nah powershell uses objects, no need to parse it out.<\/p>","upvoteCount":0,"datePublished":"2019-09-17T20:17:51.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/5","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
At first that’s what I thought. But, if I Write-Output the $ServiceTAG var, I get the headers so I thought, the Write-Output was adding that since I was running it manually on the console, but if I use the Select-Object with the “-ExpandProperty”, I get only the service tag output by the same Write-Output $ServiceTAG. Doesn’t that demonstrate the header is part of the variable?<\/p>","upvoteCount":0,"datePublished":"2019-09-17T20:25:30.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/6","author":{"@type":"Person","name":"dzee","url":"https://community.spiceworks.com/u/dzee"}},{"@type":"Answer","text":"
Thanks, Neally. I get it now. Sorry for taking us on an excursion.<\/p>","upvoteCount":1,"datePublished":"2019-09-17T20:30:17.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/8","author":{"@type":"Person","name":"dzee","url":"https://community.spiceworks.com/u/dzee"}},{"@type":"Answer","text":"
Neally is spot on here, you don’t want it renamed to the object, you want it renamed to the value of one of the object’s property, so you’d add .serialnumber<\/p>\n
Use write-host to do any debugging, probably would have saved a post here.<\/p>\n
Write-host $Object and see just what it contains<\/p>","upvoteCount":0,"datePublished":"2019-09-17T22:01:03.000Z","url":"https://community.spiceworks.com/t/rename-pc-to-serial-tag/730535/9","author":{"@type":"Person","name":"matthart5","url":"https://community.spiceworks.com/u/matthart5"}}]}}
Neally
(Neally)
September 17, 2019, 8:13pm
2
If you post code, please use the insert code button! Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don't say "Need help" or "PowerShell Help", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…
1 Spice up