Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created March 24, 2017 18:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamdriscoll/039b5303210956794abfaaebd090159c to your computer and use it in GitHub Desktop.
Save adamdriscoll/039b5303210956794abfaaebd090159c to your computer and use it in GitHub Desktop.
Create profile
function CreateProfile
{
param([String]$pszUserSid, [String]$pszUserName, [System.Text.StringBuilder]$pszProfilePath, [uint]$cchProfilePath)
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
public static class PInvoke {
[DllImport("userenv.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int CreateProfile( [MarshalAs(UnmanagedType.LPWStr)] String pszUserSid, [MarshalAs(UnmanagedType.LPWStr)] String pszUserName, [Out, MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszProfilePath, uint cchProfilePath);
}
'
[PInvoke]::CreateProfile($pszUserSid, $pszUserName, $pszProfilePath, $cchProfilePath)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment