-
-
Save crshnbrn66/699ea9ab3af437b443351e937bdd812a to your computer and use it in GitHub Desktop.
Create profile
This file contains 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
function CreateProfile | |
{ | |
param([String]$UserSid, [String]$UserName, [system.uint32]$ProfilePath) | |
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); | |
} | |
' | |
$pszProfilePath = new-object -typename System.Text.StringBuilder | |
#$pszProfilePath = $Null | |
[PInvoke]::CreateProfile($UserSid, $UserName, $pszProfilePath, $ProfilePath) | |
} | |
$stringbuff = new-object system.text.stringbuilder(260) | |
[system.uint32]$a =$stringbuff.capacity | |
$sid = ((get-aduser -id 'testuser').sid.value) | |
CreateProfile -usersid $sid -username 'testuser' -ProfilePath $a |
Need to remove the [ref]
on $pszProfilePath
on line 14
Removed the ref.. now the darn thing blows up Shell..... HMM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any pointers for this:
Cannot convert argument "pszProfilePath", with value: "System.Management.Automation.PSReference
1[System.Text.StringBuilder]", for "CreateProfile" to type "System.Text.StringBuilder": "Cannot convert the "System.Management.Automation.PSReference
1[System.Text.StringBuilder]" value of type "System.Management.Automation.PSReference`1[[System.Text.StringBuilder, mscorlib, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089]]" to type "System.Text.StringBuilder"."