Hello.<\/p>\n
I’m using this to rename PCs with:<\/p>\n
$ServiceTAG = “B311-$(”$env:computername$(get-random)“)”
\n$OLDNAME = (Get-WmiObject win32_COMPUTERSYSTEM).Name
\nRename-Computer -ComputerName $OLDNAME -NewName $ServiceTAG -force -restart<\/p>\n
But I’m finding it’s leaving first 8-10 characters of the old name the same, so I end up with a lot of PC names with very similar looking netBIOS names.<\/p>\n
I have very limited PS knowledge & I’m hoping someone can help me change the script so it will completely delete the old name, create a new randomized one and append that B311- to the beginning of the new name.<\/p>\n
The netBIOS name limitation is 15 characters, so 15 minus B311- leaves us with ten characters to randomize.<\/p>\n
Thanks for any help.<\/p>","upvoteCount":8,"answerCount":6,"datePublished":"2021-12-22T00:57:20.000Z","author":{"@type":"Person","name":"mattwestern","url":"https://community.spiceworks.com/u/mattwestern"},"acceptedAnswer":{"@type":"Answer","text":"
something like so<\/p>\n
$charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'\n\n$nameGen = \nfor($i=0;$i -lt 10; $i++){\n $charset[\"$(0..35 | get-random)\"]\n}\n\n$NewName = \"B311-$($nameGen -replace \"\\s\")\"\n$OLDNAME = (Get-WmiObject win32_COMPUTERSYSTEM).Name\nRename-Computer -ComputerName $OLDNAME -NewName $NewName -Force -Restar\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-12-22T06:53:18.000Z","url":"https://community.spiceworks.com/t/help-with-ps-get-random-command/820307/5","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"Hello.<\/p>\n
I’m using this to rename PCs with:<\/p>\n
$ServiceTAG = “B311-$(”$env:computername$(get-random)“)”
\n$OLDNAME = (Get-WmiObject win32_COMPUTERSYSTEM).Name
\nRename-Computer -ComputerName $OLDNAME -NewName $ServiceTAG -force -restart<\/p>\n
But I’m finding it’s leaving first 8-10 characters of the old name the same, so I end up with a lot of PC names with very similar looking netBIOS names.<\/p>\n
I have very limited PS knowledge & I’m hoping someone can help me change the script so it will completely delete the old name, create a new randomized one and append that B311- to the beginning of the new name.<\/p>\n
The netBIOS name limitation is 15 characters, so 15 minus B311- leaves us with ten characters to randomize.<\/p>\n
Thanks for any help.<\/p>","upvoteCount":8,"datePublished":"2021-12-22T00:57:20.000Z","url":"https://community.spiceworks.com/t/help-with-ps-get-random-command/820307/1","author":{"@type":"Person","name":"mattwestern","url":"https://community.spiceworks.com/u/mattwestern"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>