Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Created July 10, 2023 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indented-automation/e1c72ea02b87c24620217919902ad2eb to your computer and use it in GitHub Desktop.
Save indented-automation/e1c72ea02b87c24620217919902ad2eb to your computer and use it in GitHub Desktop.
CreateProfile
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