Create Local Windows 10 User Programmatically: Privacy/Advertising Settings
In this article, we will discuss how to create a local Windows 10 user via PowerShell command line and finalize the account setup programmatically, including configuring privacy and advertising settings. This is particularly useful in automated deployment scenarios where you need to create multiple user accounts with specific settings.
Creating a Local User in Windows 10 using PowerShell
To create a local user in Windows 10, you can use the New-LocalUser cmdlet in PowerShell. Here's an example command that creates a new user named "User1":
New-LocalUser -Name User1 -Password (ConvertTo-SecureString -AsPlainText 'P@ssw0rd' -Force)
In the example above, replace 'P@ssw0rd' with the desired password for the new user.
Finalizing Account Setup Programmatically
After creating a new user, you can finalize the account setup programmatically by configuring the user's profile path, adding the user to the necessary groups, and setting the privacy and advertising settings.
Setting the User's Profile Path
To set the user's profile path, you can use the New-Item and Set-LocalUser cmdlets. Here's an example command that sets the profile path for the "User1" user:
$UserPath = "C:\Users\User1"
New-Item -ItemType Directory -Force -Path $UserPath
Set-LocalUser -Name User1 -ProfilePath $UserPath
Adding the User to Groups
To add the user to groups, you can use the Add-LocalGroupMember cmdlet. Here's an example command that adds the "User1" user to the "Users" and "Remote Desktop Users" groups:
Add-LocalGroupMember -Group Users -Member User1
Add-LocalGroupMember -Group "Remote Desktop Users" -Member User1
Configuring Privacy and Advertising Settings
To configure privacy and advertising settings, you can use the Set-ItemProperty cmdlet. Here's an example command that disables telemetry and turns off targeted ads for the "User1" user:
$UserSID = (New-Object System.Security.Principal.SecurityIdentifier ($User1.SID)).Value
Set-ItemProperty -Path "HKU:\$UserSID\Software\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name "AllowTelemetry" -Value 0
Set-ItemProperty -Path "HKU:\$UserSID\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo" -Name "Enabled" -Value 0
In the example above, replace '0' with '1' to enable telemetry and targeted ads.
- To create a local user in Windows 10, use the
New-LocalUsercmdlet. - To finalize the account setup programmatically, use the
New-Item,Set-LocalUser,Add-LocalGroupMember, andSet-ItemPropertycmdlets. - To configure privacy and advertising settings, use the
Set-ItemPropertycmdlet to set the values of the appropriate registry keys.
References
- New-LocalUser (Microsoft Docs)
- Set-LocalUser (Microsoft Docs)
- Add-LocalGroupMember (Microsoft Docs)
- Set-ItemProperty (Microsoft Docs)
- How to Disable Windows 10's Telemetry and Data Collection (How-To Geek)
- How to Stop Targeted Ads in Windows 10 (Windows Central)