본문 바로가기
ICT

[PowerShell]Resetting User Password

by NeoSailer 2023. 4. 12.

[Scenario]

User requests to reset the account password becuase the user forgot the old password

 

[Objectives]

Reset the user password

 

[Steps]

User password can be eaily reset by PowerShell command "Set-ADAccountPassword"

Set-ADAccountPassword (ActiveDirectory) | Microsoft Learn

 

Set-ADAccountPassword (ActiveDirectory)

Use this topic to help manage Windows and Windows Server technologies with Windows PowerShell.

learn.microsoft.com

$username = [string, SamAccountName]
$password = [string]
Set-ADAccountPassword -identity $username -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $password -Force)

 

<Parameters>

-Identity: Identifier can distingushied name, GUID, security identifier(objectSID) , SAM account name

- Reset: Specifies to reset the password on an account. When you use this parameter, you must set the NewPassword parameter.

-NewPassword: Intended new password

 

Password can only be saved as 'SecureString' type. "Convert-To-SecureString" is a command to convert string type to 

SecureString type.

 

ConvertTo-SecureString (Microsoft.PowerShell.Security) - PowerShell | Microsoft Learn

 

ConvertTo-SecureString (Microsoft.PowerShell.Security) - PowerShell

The ConvertTo-SecureString cmdlet converts encrypted standard strings into secure strings. It can also convert plain text to secure strings. It is used with ConvertFrom-SecureString and Read-Host. The secure string created by the cmdlet can be used with cm

learn.microsoft.com

 

$stringPass = "password"
$securePass = ConvertTo-SecureString -AsPlainText -force $stringPass

$securePass.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                           
-------- -------- ----                                     --------                                                                                                                           
True     False    SecureString                             System.Object

 

* If parameter '-force' is not declared, PowerShell returns error that password cannot be protected.

$stringPass = "password"
$securePass = ConvertTo-SecureString -AsPlainText $stringPass
ConvertTo-SecureString : 일반 텍스트 입력을 보호할 수 없습니다. 이 경고를 무시하고 일반 텍스트를 SecureString으로 변환하려면 Force 매개 변수를 지정하여 명령을 다시 실행하십시오. 자세한 내용을 보려면 get-help ConvertTo-SecureString을 입력하십시오.
위치 줄:2 문자:15
+ $securePass = ConvertTo-SecureString -AsPlainText $stringPass
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [ConvertTo-SecureString], ArgumentException
    + FullyQualifiedErrorId : ImportSecureString_ForceRequired,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
반응형

댓글