Hello when I create a user in powershell with New-LocalUser
, I was wondering if there was a way to "activate" that user without connecting to it.
by "activate" I mean being able to make Windows create the users directories,registry keys, and all without manually disconnecting the current user and connecting to the newly created user.
Thank you.
Just run any process as that new user.
Here is something that will start a powershell prompt as the new user and close it. This will create the user profile folder without disconnecting you from the current session.
# Name credentials
$username = 'NewUsername'
$password = 'NewProfilePassword' | ConvertTo-SecureString -AsPlainText -Force
$credential = [PSCredential]::New($username,$password)
Start-Process powershell.exe -Credential $Credential -ArgumentList "-Command","Write-host 'Hello Profile'"