Created
July 10, 2023 07:56
-
-
Save indented-automation/e1c72ea02b87c24620217919902ad2eb to your computer and use it in GitHub Desktop.
CreateProfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -TypeDefinition ' | |
using System; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
public class UserProfile | |
{ | |
[DllImport("userenv.dll")] | |
public static extern int CreateProfile( | |
[MarshalAs(UnmanagedType.LPWStr)] string pszUserSid, | |
[MarshalAs(UnmanagedType.LPWStr)] string pszUserName, | |
[Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszProfilePath, | |
uint cchProfilePath | |
); | |
} | |
' | |
$path = [System.Text.StringBuilder]::new(260) | |
$user = New-LocalUser Test -NoPassword | |
[UserProfile]::CreateProfile( | |
$user.Sid.ToString(), | |
$user.Name, | |
$path, | |
[uint32]260 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment