PS Script to rename computer based on current logged in user and device type
Hi guys,
Can someone please help with the powershell script for changing the computer name based on current logged in user and device type.
PS: We don't have AD/DC - nothing on prem. All standalone PC's connected to AzureAD. So we will push this script down to the machine using the our MDM tool.
For example:
If the current logged in user on the PC is AzureAD\JohnSmith and Device Type is a Laptop, then the computer should be renamed as JohnSmith-L
Basically just get the parts in bold above and concatenate them and then set it as the computer name.
I've got a few bits together for getting the Name and Device Type. Just cant get my head around how to set the name as desired.
Using this if the current logged-in user is JohnSmith and is on a Laptop, it renames the machine as JohnSmith-L which is good.
However, with AzureAD joined devices the whoami returns current loggedin user as AzureAd\JohnSmith, so using above script renames the computer as: AzureAD\JohnSmith-L
2 questions here:
1. Any idea how to get rid of AzureAD\ from AzureAD\JohnSmith?
2. Is -Restart absolutely necessary OR if not will it just take effect when it restarts next (which is ideal)?
Shaun Vermaak
Any idea how to get rid of AzureAD\ from AzureAD\JohnSmith?
Open in new window
What do you want for device type, the chassis?