Bug:New-PSDrive altering stored username in registry persistence entry when using credential object from different domain in UPN format
# Steps to reproduce
# Must use the format username@domain for username and be mapping share from different non-federated domain to reproduce
$Cred = Get-Credential
$Path = 'Path to the share'
New-PSDrive -Name 'P' -PSProvider FileSystem -Root $Path -Persist -Credential $Cred -Scope Global
# Expected behavior
The $Cred.username value gets stored in the registry under HKEY_CURRENT_USER\Network\P
in the UserName string value without alteration.
# Actual behavior
The domain of the system running the commands gets appended in the front of the username from the cred object when stored in the reg key.
This causes issues with persistence when mapping drives from another domain due to the system trying to authenticate against the wrong domain.
This behaviour only happens when mapping a drive using credentials from a different domain with the username in the format 'firstname.lastname@example.org' being passed to New-PSDrive as a credential object. It does not happen when the credential object has the username in the format domain1\username, when specifying the username in the command and entering it into the popup, or when using a credential object for the same domain the system running the commands belongs to.