Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. param (
  2. [string]$oldPassword = $( Read-Host "Old password"),
  3. [string]$newPassword = $( Read-Host "New password")
  4. )
  5.  
  6. $ADSystemInfo = New-Object -ComObject ADSystemInfo
  7. $type = $ADSystemInfo.GetType()
  8. $user = [ADSI] "LDAP://$($type.InvokeMember('UserName', 'GetProperty', $null, $ADSystemInfo, $null))"
  9. $user.ChangePassword( $oldPassword, $newPassword)
  10.  
  11. param (
  12. [string]$oldPassword = $( Read-Host "Old password"),
  13. [string]$newPassword = $( Read-Host "New password")
  14. )
  15.  
  16. $MethodDefinition = @'
  17. [DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
  18. public static extern bool NetUserChangePassword(string domainname, string username, string oldPassword, string newPassword);
  19. '@
  20.  
  21. $NetAPI32 = Add-Type -MemberDefinition $MethodDefinition -Name 'NetAPI32' -Namespace 'Win32' -PassThru
  22.  
  23. $NetAPI32::NetUserChangePassword('.', $env:username, $oldPassword, $newPassword)
  24.  
  25. ([ADSI]'LDAP://CN=User,CN=Users,DC=domain').ChangePassword('currentpassword','newpassword')
  26.  
  27. $MethodDefinition = @'
  28. [DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
  29. public static extern ***long*** NetUserChangePassword(string domainname, string username, string oldPassword, string newPassword);
  30. '@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement