Scripts to rename workstation they are prepared by Intune Autopilot in Hybrid Azure AD Join. App renaming device based on Device Name from Windows Autopilot devices list. Devices – Enroll devices – Devices - select device - Device Name field
Many thanks to MICHAEL NIEHAUS. Solution was based on: https://oofhours.com/2020/05/19/renaming-autopilot-deployed-hybrid-azure-ad-join-devices/
Delegate access to SELF for "Read All Properties" and "Write All Properties" to OU with autopilot devices
.\IntuneWinAppUtil.exe -c ..\App -s install.cmd -o ..\IntuneApps
Next add Windows app (Win32) and load install.intunewin file.
Install command: install.cmd
Uninstall command: uninstall.cmd
Install behavior: System
In install.cmd we will start main app script. Script can use additional param: -Strict - Strict mode will use exact device name from profile, without any sufix if name is used. But it may generate error if device name exist in AD.
Additional requirement detects if new device name exist in profile settings, device is part of domain and aktually device have connection to domain controller. If not, app is not applicable for now.
Additional requirement rules: Script PSRenameReq.ps1
Select output data type: Boolean; Operator: Equals; Value: Yes ($true)
Detection rules check if current name is different from new.
Detection rules: PSRenameDetector.ps1
Required but not in autopilot proces. It must be excluded from ESP - we dont want to reboot device in autopilot process.
App will start when autopilot ends and device connect to corporate network. If we dont have connection to corporate network, Intune try to start it later.