Site Tools


change_domainpassword_via_powershell

Hier ein Script um einem Useraccount ein neues Passwort in der Domäne zu setzen

changeuserpassword.ps1
<
Write-Host 
Write-Host "Set new Useraccount Password" -foreground "yellow"
Write-Host
 
$cmdlet = "ActiveDirectory" 
if ( (get-command -Name $cmdlet -ErrorAction SilentlyContinue) -eq $null ) {Import-module ActiveDirectory} 
 
$ExecUser = ([Environment]::UserName) 
 
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$ScriptPath = Get-ScriptDirectory
 
$User = Read-Host -Prompt "Provide User Name"
 
$Password = (Read-Host -Prompt "Provide New Password" -AsSecureString) 
 
Write-Host "Set Change Password at Next Logon?"
 
Write-Host "Press Y for Yes" -foreground "yellow" 
Write-Host "Press N for No" -foreground "yellow"
write-host
 
$auswahl = read-host -Prompt "Set Change Password at Next Logon?"
 
 
if ($auswahl -eq "Y") {Set-ADAccountPassword -Identity $User -NewPassword $Password | Set-ADuser -ChangePasswordAtLogon $True}
else {Set-ADAccountPassword -Identity $User -NewPassword $Password}
 
get-aduser -identity $User -properties passwordlastset, passwordneverexpires | sort name | ft Name, passwordlastset, Passwordneverexpires
write-host
change_domainpassword_via_powershell.txt · Last modified: 2019/02/11 17:17 by 192.168.1.1