I've changed my username in Windows 10, and now I need to automate getting this changed username as a Powershell script But everything I try returns my old username apart from some AD-related query.
Example:
$env:UserName
whoami
$(Get-WMIObject -class Win32_ComputerSystem | select username).username
Return my old username while my user was actually renamed.
Because of this I can't relatively get correct username to use in PS scripts.
Only thing that was able to extract it was this:
([adsi]"WinNT://$env:userdomain/$env:username,user").fullname
But on other machine it just returns empty result