Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param (
- [string]$oldPassword = $( Read-Host "Old password"),
- [string]$newPassword = $( Read-Host "New password")
- )
- $ADSystemInfo = New-Object -ComObject ADSystemInfo
- $type = $ADSystemInfo.GetType()
- $user = [ADSI] "LDAP://$($type.InvokeMember('UserName', 'GetProperty', $null, $ADSystemInfo, $null))"
- $user.ChangePassword( $oldPassword, $newPassword)
- param (
- [string]$oldPassword = $( Read-Host "Old password"),
- [string]$newPassword = $( Read-Host "New password")
- )
- $MethodDefinition = @'
- [DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
- public static extern bool NetUserChangePassword(string domainname, string username, string oldPassword, string newPassword);
- '@
- $NetAPI32 = Add-Type -MemberDefinition $MethodDefinition -Name 'NetAPI32' -Namespace 'Win32' -PassThru
- $NetAPI32::NetUserChangePassword('.', $env:username, $oldPassword, $newPassword)
- ([ADSI]'LDAP://CN=User,CN=Users,DC=domain').ChangePassword('currentpassword','newpassword')
- $MethodDefinition = @'
- [DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
- public static extern ***long*** NetUserChangePassword(string domainname, string username, string oldPassword, string newPassword);
- '@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement