coolslim54 Posted August 27, 2016 Report post Posted August 27, 2016 Currently running SCCM 1511 with MDT 2013 integrated. We are looking to refresh all machines (desktops and laptops) from Win 7 to Win 10. My MDT Task Sequence works well, but I'm looking for a way to change the first 3 characters of the computer names. We have a standard naming convention, Example: current name looks like TW7NSDA-002-0000. The TW7 reflects Win 7. Is there a simple script I can implement in the Task Sequence to change TW7 to TW10 so the new computer name would reflect TW10NSDA-002-0000? Thanks! Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted August 28, 2016 Report post Posted August 28, 2016 This should work (I haven't tested it because im not at work atm) $var = New-Object -ComObject Microsoft.SMS.TSEnvironment $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("TW7", "TW10") Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted August 30, 2016 Report post Posted August 30, 2016 Thanks! I'll give it a shot! Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted October 22, 2016 Report post Posted October 22, 2016 Tregelen, did you ever get a chance to test it? I tested the script before adding it to my task sequence and it came back with errors. Quote Share this post Link to post Share on other sites More sharing options...
YPCC Posted October 22, 2016 Report post Posted October 22, 2016 How did you test it? It has to be run with the Task sequence environment (New-Object -ComObject Microsoft.SMS.TSEnvironment), so if all you did was run the VBS in windows that it wouldn't work. Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted October 23, 2016 Report post Posted October 23, 2016 It worked for me doing it during the task sequence. As YPCC said if you just run the script while in the OS then it wont work as the com object (Microsoft.SMS.TSEnvironment) wont be able to load. If you run it during the task sequence then it will work. And make sure you running it as a PowerShell script during the task sequence. Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted October 24, 2016 Report post Posted October 24, 2016 Thanks for your responses. My PowerShell skills are terrible at the moment, but I'm working on it...I'll give it a shot and follow up. Thanks again! Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted October 25, 2016 Report post Posted October 25, 2016 Man, you guys are "da truth"!! Script worked like a charm! Many thanks! I'll definitely be keeping that one. Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted October 25, 2016 Report post Posted October 25, 2016 Happy to help Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted November 11, 2016 Report post Posted November 11, 2016 Tregelen, If I wanted to add an additional line in the script to reflect laptops, could I just add the line at the end to look like this $var = New-Object -ComObject Microsoft.SMS.TSEnvironment $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("TW7", "TW10") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("LW7", "LW10") Or would I need to add and elseif statement? I would think that it would ignore line 3, if nothing matches with what the script is looking for.... Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted November 11, 2016 Report post Posted November 11, 2016 That will work, or you could add in an additional .Replace on the same line. It technically wont skip that line, it will still run it it just doesnt find that string to replace. $var = New-Object -ComObject Microsoft.SMS.TSEnvironment $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("TW7", "TW10").Replace("LW7", "LW10") Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted March 14, 2017 Report post Posted March 14, 2017 Tregelen, It's me again! The script you provided above works great! Just one last step. How can I remove the first dash from TW7NSDA-002-0000? Again, many thanks! Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted March 14, 2017 Report post Posted March 14, 2017 Try this $var = New-Object -ComObject Microsoft.SMS.TSEnvironment [regex]$pattern = "-" $var.Value("OSDComputerName") = ($pattern.replace($var.Value("OSDComputerName"), "", 1)).Replace("TW7", "TW10").Replace("LW7", "LW10") Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted March 15, 2017 Report post Posted March 15, 2017 Gave it a shot and the task sequence failed at powershell script step with error code 0xFFFD0000. Do I need to set the OSDComputerName variable like before? $OSDComputerName = $var.Value("OSDComputerName") Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted March 15, 2017 Report post Posted March 15, 2017 That is interesting, it worked for me. Are you running it as 'Bypass' in the TS step? Are you able to F8 and do the steps manually? I was just able to do the commands in my VM and it worked fine. I will try it as a step instead of manually and see if I get the same result. Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted March 16, 2017 Report post Posted March 16, 2017 Definitely running the script as bypass in the task sequence. I'll try the manual steps tomorrow at work. Thx! Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted March 16, 2017 Report post Posted March 16, 2017 It appears to work manually, but fails in the task sequence. Quote Share this post Link to post Share on other sites More sharing options...
tregelen Posted March 16, 2017 Report post Posted March 16, 2017 Ok, I will see what I can work out with it and get back to you. Quote Share this post Link to post Share on other sites More sharing options...
coolslim54 Posted March 20, 2017 Report post Posted March 20, 2017 I also tried the following and received the same error mentioned above in my task sequence: $var = New-Object -ComObject Microsoft.SMS.TSEnvironment [regex]$pattern = "-" $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($pattern.replace($var.Value("OSDComputerName"), "", 1)).Replace("TW7", "TW10").Replace("LW7", "LW10") Quote Share this post Link to post Share on other sites More sharing options...
Rocket Man Posted March 31, 2017 Report post Posted March 31, 2017 If you wish to rename prior to OSD within windows you could do it through WMIC command. This will allow you to remove the dashes as needed. The only downside is that you will need to create a extensive batch file if a large amount of PCs needs to be changed, oldname and new desired name but with excel you can do this easily and export. Syntax WMIC ComputerSystem where Name="XX-XXX-PC01" call Rename Name="AABBB-PC01" WMIC ComputerSystem where Name="XX-XXX-PC01" call Rename Name="BBCCC-PC01" WMIC ComputerSystem where Name="XX-XXX-PC01" call Rename Name="CCDDD-PC01" Create a package with batch file as above - create custom TS and copy script locally to all desired PCs from within the TS then use run command line to execute batch file locally at each PC and use an account that has domain rights to execute script in run command line. Place restart command in TS and then you could do another run command line to execute a DDR to update the CMDB with new names when the systems start backup from previous restart. WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000003}" /NOINTERACTIVE execute a delay of a 2-3 minutes so that the systems has time to update information to site server after the DDR has executed and then do another restart to update the DNS records of each systems change if you want remote control to work immediately etc... You'll need to update the collections in the console after all is finished to reflect name changes. Not the most convenient way of achieving this but will work - and works in windows which is a bonus. Quote Share this post Link to post Share on other sites More sharing options...
djm1k0 Posted November 7, 2017 Report post Posted November 7, 2017 On 8/28/2016 at 7:14 PM, tregelen said: This should work (I haven't tested it because im not at work atm) $var = New-Object -ComObject Microsoft.SMS.TSEnvironment $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("TW7", "TW10") Hi i am trying to do this same tasks except for different computer names i need help .. so am i taking the code below and creating a package w/ or without program? Do i save the code as .ps1 then in my TS I add-->general-->Powershell Script? choose the package i created the script name below as .ps1 and choose bypass ? in what stage of the TS do i run this as i cannot get it to work ? Help would be greatly appreciated in getting this working. Also is there another way i can create a program or package per se and then just deploy it to a Lab already in production that just needs thier names changed from like H206 to H205 the room number has changed in the computer names. $var = New-Object -ComObject Microsoft.SMS.TSEnvironment $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("TW7", "TW10") Quote Share this post Link to post Share on other sites More sharing options...
djm1k0 Posted November 8, 2017 Report post Posted November 8, 2017 20 hours ago, djm1k0 said: Hi i am trying to do this same tasks except for different computer names i need help .. so am i taking the code below and creating a package w/ or without program? Do i save the code as .ps1 then in my TS I add-->general-->Powershell Script? choose the package i created the script name below as .ps1 and choose bypass ? in what stage of the TS do i run this as i cannot get it to work ? Help would be greatly appreciated in getting this working. Also is there another way i can create a program or package per se and then just deploy it to a Lab already in production that just needs thier names changed from like H206 to H205 the room number has changed in the computer names. $var = New-Object -ComObject Microsoft.SMS.TSEnvironment $OSDComputerName = $var.Value("OSDComputerName") $var.Value("OSDComputerName") = ($OSDComputerName).Replace("TW7", "TW10") I knew this was a super old post, but hoping to bring it back to life. BUMP Quote Share this post Link to post Share on other sites More sharing options...