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
The $Cred.username value gets stored in the registry under HKEYCURRENTUSER\Network\P
in the UserName string value without alteration.
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.
For example if $Cred.Username is 'username@Domain1.com' and the computer running the command is on Domain2, the value stored in the reg key is 'Domain2<a rel="nofollow noreferrer" href="mailto:username@Domain1.com">username@Domain1.com'.
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.