question

GhGh-0482 avatar image
0 Votes"
GhGh-0482 asked DSPatrick answered

windows server 2019 - user password change

Hi,
In my windows 2019 server, there are 20 users.
The users password is the same for everyone.
I need to change the password for all users on a daily basis.

can someone help me with a script?
Thank you
GH

windows-server
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered

Is the server core or desktop experience? Something may be broken on this server, might try another

99495-image.png



image.png (20.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GhGh-0482 avatar image
0 Votes"
GhGh-0482 answered

Windows erver 2019

PS C:\Users\Administrator> $PSVersionTable.PSVersion

Major Minor Build Revision


5 1 17763 1852

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered

What OS are you running the PowerShell on? You'll need WMF version 5.1 to have the LocalAccounts module so I'd check $PSVersionTable.PSVersion


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GhGh-0482 avatar image
0 Votes"
GhGh-0482 answered

Hi,
I run the program:
$ Password = Read-Host -AsSecureString
$ UserAccount = Get-LocalUser -Name "user030"
$ UserAccount | Set-LocalUser -Password $ Password

which asks me for the password
I type the password: 123Test)
and I get this error:
Get-LocalUser : The term 'Get-LocalUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:2 char:16
+ $UserAccount = Get-LocalUser -Name "user030"
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-LocalUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Set-LocalUser : The term 'Set-LocalUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:3 char:16
+ $UserAccount | Set-LocalUser -Password $Password
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-LocalUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

where I'm wrong?

Thanks for your help

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered DSPatrick edited

That doesn't look right
PS C:\> $Password = Read-Host -AsSecureString ---this line prompts for a new password, then the password is stored as a secure string in the $Password variable
PS C:\> $UserAccount = Get-LocalUser -Name "User030" ---this line gets a user account named User030
PS C:\> $UserAccount | Set-LocalUser -Password $Password ---this line sets the new password on the user account



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GhGh-0482 avatar image
0 Votes"
GhGh-0482 answered

Thank you for your answer.

I don't know powershell.
I tried to change the password.
To user "user030" I have to put this password: 123 (Test):

$Password = Read-Host -AsSecureString
$UserAccount = Get-LocalUser -Name "user030"
$UserAccount | Set-LocalUser -123(Test) $Password

but the script gives me this error:

Get-LocalUser : The term 'Get-LocalUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:2 char:16
+ $UserAccount = Get-LocalUser -Name "user030"
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-LocalUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Set-LocalUser : The term 'Set-LocalUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:3 char:16
+ $UserAccount | Set-LocalUser -Password $Password
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-LocalUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.