Search code examples
powershellregistrysettings

Modifying new user registry in Powerhsell


I'm writting here because this problem is making me crazy.

I'm coding a script to configure a new windows installation. Due to company rules it must be done in Powershell and no windows policies can be used.

I must create a new user and modify (via registry) a couple of configurations. No issue with those topics. Windows 10 creates the user registry file ntuser.dat once the user is logged in for the first time. My problem is that I wanted to modify the registry without ever logging in this new user. I thought I could start a job or a process in the background as the user to trigger the file generation. But it seems it's not working at all:

$USERNAME = $cfgData.cfg.userSettings.userName
$USERPWD = ConvertTo-SecureString -String $USERNAME -AsPlainText -Force
$PC_USER = $env:COMPUTERNAME + "\" + $USERNAME

$userCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $PC_USER, $USERPWD
$output = Start-Job -ScriptBlock { Get-Process -Name explorer } -Credential $userCreds -Verbose
Wait-Job $output | Out-Null

It looks like I can edit the registry but once I log in for the first time with the user, no changes were made.

Any ideas are welcome! I thought about scheduling a task to be performed once the user logs in for the first time, but I have no idea where to start with if I choose this way of solving this problem.

Thx in advance for your time!

Ben


Solution

  • Just to keep everything posted.

    I tried the solution from @Jeff Zeitlin (modify the default user NTUSER.DAT file) and it worked like a charm. Thank you Jeff!

    Ben