Last active
September 4, 2019 15:49
-
-
Save JonathonAnderson/d6f510acf60723973a8e6b94d52be368 to your computer and use it in GitHub Desktop.
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
Add-Type -Namespace Import -Name Win32 -MemberDefinition @' | |
[DllImport("advapi32.dll", SetLastError = true)] | |
public static extern bool LogonUser(string user, string domain, string password, int logonType, int logonProvider, out IntPtr token); | |
[DllImport("kernel32.dll", SetLastError = true)] | |
public static extern bool CloseHandle(IntPtr handle); | |
'@ | |
$Global:ImpersonatedUser = @{} | |
$tokenHandle = 0 | |
$Username = "NT AUTHORITY\NetworkService" | |
$Password = $null | |
$Domain = $null | |
$LogonType = 3 | |
$LogonProvider = 0 | |
$returnValue = [Import.Win32]::LogonUser($Username, $Domain, $Password, $LogonType, $LogonProvider, [ref]$tokenHandle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment