0

Trying the low-impact solution as mentioned in the post:

how can I programmatically cause a new windows users profile to be created

Suggestion was to run a command as that user using psexec.exe for Windows to create the profile:

psexec.exe -u <domain/user name for AD user> -p <password> cmd.exe /c exit

I'm running it local to the VM I've created. Getting the message :

PsExec could not start cmd.exe:
The user name or password is incorrect

Can someone give me insight into what I'm doing wrong? My purpose is to create the user folder in the C:\Users area based upon the AD user I set up, without them or me having to log in to toggle this user folder creation.

Mr R
  • 103

2 Answers2

0

You might have a look at this ansible module - win_user_profile. The powershell script (which is the ansible module) can be found here: https://github.com/ansible-collections/community.windows/blob/3afe02165344bf46534a9b56766e68531addac43/plugins/modules/win_user_profile.ps1

Of interest to you would be lines 35-58 (where the Ansible.WinUserProfile.NativeMethods class is created) and 130 to 146ish. You could base your own process off of this, or at the very least it would point you in one direction to achieve what you seek.

Semicolon
  • 2,108
0

This is a bit old of a thread but I came upon it while looking for a way to create a user's profile folder structure properly during a new image build script for specific customization that were not possible by GPO etc.

If you run a remote powershell Invoke-Command with the user's credentials, it will build the user profile folder under C:\Users if it doesn't already exist and you can then manipulate it and also the HKCU registry keys as needed.

This command does nothing but the exit command, but will create the user's profile if it doesn't already exist:

Invoke-Command -ComputerName $computerVar -ScriptBlock {exit} -Credential $credentialVar

Obviously the user's creds have to have the rights to connect remotely, and the OS firewall can't be blocking said connections but otherwise, this command will do what you are looking for at least.