Push registry key with Intune - PowerShell script to rename 'This PC' to devices Computer Name

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign friends this is going to be a really cool video and we're gonna do multiple things we're going to send the script who run the registers change and what this Registries change does is that it's going to change you see on this virtual machine here it says this PC and the under there you have the disk this text this PC is saved in the registry and we're gonna change that to the computer name of the machine so we're going to send this script to all our machines so instead of seeing this PC we will see the machine name instead well the computer name so this is something you can use in real world this is um good so you could send this to your company's machine so you easier see the machine name when you're on it because honestly this PC is good for nothing so let's see where is this value stored or this piece is not always stored it's the default one so we can see let's open the registry we can speak a bit about the registry also so the registry is basically a lot of settings in here so in the old days before Windows 95 actually you didn't have the registry you have everything saved ini file but the register came and on Mac OS you have pl-list it's sort of the same thing so instead of saving a lot of small files everywhere unifies it's saved in one place the registry the registry however is built up by many parts as you see here I prefer to see it built up by two parts one is the machine and one is the user so the user part if I am a current user here all that comes from my users profile so if I would go into my own profile here C users and John brins now we're not seeing um hidden files but if we would see hidden files let's show everything don't hide anything I want to see everything who's in there you're gonna see uh some extra files here here we actually have an ini file but here emptyuser.dat so this is my um part don't delete this one by the way this is where everything in the user part it's called the Hive the user Hive so you see in the registry you have user current users if I log in as another user you have different values so this is per user whereas hkey local machine it's the same for everyone so this is gold for troubleshooting for example if you have a problem and you log off to user and log back in another user and the problem is gone then you know it's within the user profile or within the user part of the registry if the problem persists you know that it's not related to the user then it's HQ local machine or program files or outside but okay let's not go too far so we wanted to see where uh this PC where we can change that well it's gonna be under HQ local user software and software explorers by Microsoft so it's going to be Microsoft then the next part is less logic it should be under Windows well Windows Explorer is under windows then it's current version on the current version now it comes logic again because here it's actually under Explorer and then it becomes unlogic again because it's under clc'd and you might have a multiple here it's actually the top one doesn't that always have to be the top one but it's this good so here if we change this value if I just double click here and put the John Prince and I would save it then actually this PC would change to that name so it's this key we're going to change but we're going to do it with a script and the icon comes from this file so I'll show that also the video is going to be a little longer than I thought now finally but that's I think it's good to go through that so if I uh let's say this folder Java I want another folder icon than this and I would prefer to still see the registry can we see the register at the same time yep so this is just the default icon if we right click here and take a proper case and then do customize over here you see we can change the icon but what should we change it to well you see here it's on the Windows system 2 image resource and here it stakes from the shell so let's change that we can even browse so we want to browse the image resource image this one you see it map here and what minus 109 it's probably you see it come up here so if we click on another one it's going to take another number what should we take for our Java here so you have a few I'm gonna take um I have no idea actually I take a legacy CD here so if I hit OK here you see that um the icon change but not only that under the Java it's going to create a desktop ini if we double click on this we're gonna open a notepad we're gonna see it's gonna be images and the number that correspond to this icon that I choose so in this case it's 131 and I said I just say earlier that desktop ini that's Legacy it is Legacy I mean most settings are in the registry you will still see a few uni files why they have in its because this one is apparent to this folder so it's desktop.in is only for this folder up here but that that again a little sidetracked so what we want to do is not to change the icon or anything we're fine with the computer icon in this PC we don't want to change this PC icon even though we could we want to change this PC name so we have found the path so let's take this pattern and I'm gonna create the script on the other machine so let's do a Powershell ISE let's start a partial IC we can run it as admin don't actually need to run that as admin see if it remembers some old scripts most likely so let's do some cleaning that was from previous videos cleaned up so I'm just gonna paste down here it's not a command but it's the path so let's start our script so we're going to upload a script to InTune that's gonna run it's gonna run as the user it must because if we're on a system it can't reach here and it's going to change this PC to the machine name now I said a million of time so let's say the purpose rename it's called this PC right to the computers computer name and as always I put the author X itself output the date right here after we are the fourth Fourth of July congratulations United States on Independence Day and I'll put version also I don't always do that so first let's put the variable variables we need one who will store the computer name so all variable starts with a dollar so we do a dollar I'll call dbn Computer name wow computer name not so important what the name is then you do dollar e and V those are the built in you see I get a lot of different variables here so I can get where the common program files path is and well I want computer name so we we could get a lot of other data here if we wanted but obviously we wanted a computer name so if we run only this part let me do that I select that one and run this part here f8 so it just run it didn't do anything other than get my machine name so if I would run a host here in computer name I would see the computer name so this is the value that we want to put for this key here so how do we do that well to set registry we can do set item property here we got that one and we first need the path yes and we have the path under here but that's not the friendly one so we can do h Key current user see if it accept that I need a k right I said hkey current user and here we actually get the path so now it's a bit hidden here but I'll remember this one by heart so it's gonna be should be software yes software and now we see it again it's gonna be Microsoft after uh that went too far Microsoft then it's going to be windows I mean I could copy down there but I like this way because then you're sure it's the good one and then it's gonna I'll I can start to type at least I don't have to browse it and then Explorer then CLI and here you're very happy to have well it's the top one on this machine as well so under here that's our path now what's the name of the key well this one is very specific the name of the keyword that we need because I need because it's actually parent is default so let's put that in the double quotation so parent is default and here comes what is the value well the value it's the computer name and the computer name it's we store that here so it's going to be gbn computer name so I'm just going to copy this one and if it doesn't already have a value it's going to prompt the user hey are you sure so we're going to add a little Force at the end so I'm going to delete the last line here we don't need that that was just to verify of the good path this could error out so it's good practice to do a try so you actually try and then you try whatever is in between the brackets and if it fail then you have to catch that see catch the failure and if it's fail we already know it's bad so then we want to report that back then we can exit with one exit with zero means success so let's see we could actually write so here we know it works if the try doesn't give an error so we can do right host we successfully renamed this PC today computer name not sim not so important we can also here use something we could do right host but we can also do write warning and what do we write well we write whatever it pick as exception so this is a bit advanced exception Dot message so what if it try and fails it's going to give an exception and a message we just write that out so I think we have a script who works now so the most important is that this line here nine is that we write into this key on the default key value we put in the computer name so if I go back to my virtual machine here we want to go to this key here we want to change the value of the name well we want to change the data and we want to put that to whatever machine name we have so we'll keep this one this is the machine we're probably gonna test it on so now this file is ready let's see if we get give if it works okay so we need to save this now um I'll save this one in Not In Tune packages so we have one for script I have one for Powershell script let's call this one I'll prefix it gbn update this PC with computer name save this one Powershell ISE is not the best tool I like it because it's always installed on all machines um let's see I just wanted to open this file in notepad plus plus in order to clean it because of an encoding I mentioned that in many videos but so if I open we have under gbn Powershell Scripts here in Powershell ISE for some reason it took the encoding to UDF boom and it's better with utf-8 only so I'll resave it like that okay hopefully this works so we go into our InTune console we go to intune.microsoft.com we'll log in let's see if I zoom in a bit we go to devices under devices we have scripts not the first time we have been here we've been here in the previous videos we have one for mac and one for Windows so let's add a new one we do it for Windows 10 and later let's call this one gbn rename this PC to computer name sometimes description is the same this script will change on this PC in Explorer to match the computer name of the device oh it seems I have some issues here we'll see if I will have to redo everything and go next oh looks like looks like I should be good gbn so we go to our script so it's this one here you don't get the preview here so be sure you have good names I know it's the correct one normally we run it as systems we don't have to change anything but as mentioned several times I repeat it again since this is under H Key current user we must run it as the user and user have permission here not all users have permission outside here in hkey local machine but under user users have it there are a few nodes where you don't have the permission so we actually want to run as the user that's fairly rare I would say enforce no 64-bit yes we don't have any signature who verified that this is a trusted so don't check yes here then that's gonna fail then I want to assign this to well all my Windows machine do I have a group for all my windows I have all windows devices there is no idea to Target the my Mac or Linux devices or other and it's ready to go so it is assigned no well it is but you have to do refresh yes okay so it's ready to go so let's go to our device again for the millionth time this PC says this PC so let's see we can do a company portal and then sync this device I have a video on how to sync we could wait but but we want it to happen sooner than later so now it's syncing scripts run before win32 apps important to know that we aren't deploying anywhere in the 32 apps in this video [Music] [Music] and we got exit code 0 that means it succeeded so let's see here now if we do a little refresh we have the machine name so the script have worked you see this is the machine name we can see that in in other ways right so if we right click here and take the properties so it have updated we see here is the machine name so it if we wanted to rename so we have successfully run this so it have worked it's going to take a little while before um this one realized that this one worked so right now it probably doesn't know or maybe it does no not yet but this one is going to catch up actually this one have succeeded right now so I guess this one's gonna pick up in a few minutes so a quick recap we created a Powershell script that changed this registry value to this and we push that under the user context so now all the machines in the company to run this instead of this PC it will show up the computer name which is much more useful so thank you very much for following along this video see you in the next one have a great day
Info
Channel: Intune & Vita Doctrina
Views: 4,249
Rating: undefined out of 5
Keywords: Intune, Registry, PowerShell, Script
Id: qGzkiNrHTPw
Channel Id: undefined
Length: 19min 29sec (1169 seconds)
Published: Fri Jul 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.