Get-LocalUser doesn't work with Microsoft Account as documented

0

1

According to the article Get-LocalUser, the syntax to get a Microsoft local account from PowerShell is:

Get-LocalUser -Name "MicrosoftAccount\myemail@outlook.com"

Except when I run this, I get the following error:

Get-LocalUser : User MicrosoftAccount\myemail@outlook.com was not found.

However, the account is definitely there. What am I missing here?

enter image description here

Later... I removed the account manually and then ran the following:

New-LocalUser -Name "MicrosoftAccount\myemail@outlook.com" -Description "Local account"

And then got this error message:

New-LocalUser : Cannot validate argument on parameter 'Name'. The character length of the 48 argument is too long. Shorten the character length of the argument so it is fewer than or equal to "20" characters, and then try the command again.

The actual email I'm using is reasonably long as it's of the form firstname.lastname-company@outlook.com - I wonder if there is an very old character limit in there somewhere from when local accounts were limited in length?

munrobasher

Posted 2019-04-09T12:03:20.180

Reputation: 640

To restrict Get-LocalUser output to MicrosoftAccounts use Get-LocalUser | Where-Object PrincipalSource -eq 'MicrosoftAccount' The name for that Account here doesn't contain the email though. – LotPings – 2019-04-09T12:46:11.263

Answers

0

Closing this one off quickly - it's a limitation of the *LocalUser cmdlets which are limited to 20 characters. This article flags it as a documentation bug...

New-localuser cmdlet fails length check on Name parameter

munrobasher

Posted 2019-04-09T12:03:20.180

Reputation: 640