when i am trying to run ([adsi]"WinNT://$env:ComputerName/$Username").SetPassword($Password)
command i am getting below error.
The following exception occurred while retrieving member "SetPassword": "The group name could not be found." At D:\Install\ScriptsP12\3.InstallSQL2016.ps1:9 char:1 + ([adsi]"WinNT://$env:ComputerName/$Username").SetPassword($Password... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException + FullyQualifiedErrorId : CatchFromBaseGetMember
I even tried the answer from "Using Powershell and ADSI to set local passwords" with no luck. Any help would be greatly appreciated.
Thank you.
If Microsoft.PowerShell.LocalAccounts module is available on your system, you can try following code instead.
$UserAccount = Get-LocalUser -Name $Username
$UserAccount | Set-LocalUser -Password $(ConvertTo-SecureString -String $Password -AsPlainText -Force)
Hope it helps!