14

How can I create a new local user account on Windows 8 associated with a Microsoft email account (e.g. MicrosoftAccount\[email protected]) programmatically, using PowerShell or another scripting language available on Windows. The script will be provided with the email address and password for the Microsoft account.

Thanks in advance for your help!

4
  • You're going to pre-create the email/MS accounts, and you're just looking to create a new Windows user and associate them to that email/MS account, correct? Have you tried using the traditional "Net User" command(s)? Jul 16, 2013 at 18:17
  • 1
    @techie007 Yes, in the current case all Microsoft email accounts are already pre-created. But upon reading your comment, I realized it would be very useful for me to be able to create these accounts programmatically. So, if anybody know how to do that, please include it in your answer. Thanks! Jul 16, 2013 at 18:27
  • Automating the creation of email accounts on MS's site would be off-topic for here, that's why I wanted to get clarification on what parts you are trying to automate. :) Aside form that, what exactly have you tried already? Where are you getting stuck in your scripting? Jul 16, 2013 at 18:32
  • @techie007 I am quite a newbie in PowerShell scripting, basically only familiar with filesystem/registry/ACL manipulation, general pipelining and scripting constructs and .NET/COM interop. Jul 16, 2013 at 19:38

2 Answers 2

3

Windows accounts associated with Microsoft accounts are just normal Windows accounts with a little bit extra information added to them in the SAM.

You first use your favourite method to create your new accounts (net user, PowerShell, WMI) and then add the extra information to the new accounts.

This is actually rather tricky to do, because Microsoft does not provide a public API for it. Luckily someone did all the hard work for us. This blog post explains the details and provides a PowerShell script to add the additional information.

0

Yes, creating the Live account automatically is against TOS for the Live service thus off topic here. But I think what you are looking for is this:

# Create new local Admin user for script purposes
$Computer = [ADSI]"WinNT://$Env:COMPUTERNAME,Computer"

$LocalAdmin = $Computer.Create("User", "LocalAdmin")
$LocalAdmin.SetPassword("Password01")
$LocalAdmin.SetInfo()
$LocalAdmin.FullName = "Local Admin by Powershell"
$LocalAdmin.SetInfo()
$LocalAdmin.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
$LocalAdmin.SetInfo()

Or you can use the old method:

Another alternative is the old school NET USER commands:

NET USER username "password" /ADD

OK - you can't set all the options but it's a lot less convoluted for simple user creation & easy to script up in Powershell.

NET LOCALGROUP "group" "user" /add to set group membership.
1
  • Where exactly in the script the user account being created is associated with a pre-created Microsoft e-mail account? I assume that the e-mail account password should be provided in some place, right? Aug 5, 2013 at 17:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .