Jump to content
StephenTheTech

Force local user account password change

Recommended Posts

I have been beating my head against this for a while. I can these commands locally and they work fine, but when I use Pulseway they throw errors on the variable for the username. I have tried running all in one script from powershell and I have broke it up in to two scripts the first 2 line being in powershell (which works as intended) and the second line in batch (also tried running manually from terminal). Im sure there is something small I am doing wrong and I would appreciate the help, thanks

 

$user= get-wmiobject-class win32_computersystem | select-object username
wmic UserAccount where name=$User set Passwordexpires=true
net user $env:USERNAME /logonpasswordchg:yes

 

I dont have a domain for GPO

Share this post


Link to post
Share on other sites

Hi Stephen,

At a quick glance I do notice a space missing before the -class in the first line. Maybe this is the error you're seeing?

-Paul

Share this post


Link to post
Share on other sites

$user= get-wmiobject -class win32_computersystem | select-object username
wmic UserAccount where name=$User set Passwordexpires=true
net user $env:USERNAME /logonpasswordchg:yes

 

I typed it wrong that time, this is copy and pasted from Pulseway. My problem isnt with lines 1 and 2....line 3 is broke, more specifically the username variable is broke

Edited by StephenTheTech

Share this post


Link to post
Share on other sites

Well $env:USERNAME relies on the current user and Pulseway runs in the context of the SYSTEM account. Try using this instead:

$user= get-wmiobject -class win32_computersystem | select-object username
wmic UserAccount where name=$user set Passwordexpires=true
$username = $user.username
if ($username -like '*\*')
{
    $idx = $username.LastIndexOf('\')
    $username = $username.Substring($idx + 1)
}
net user $username /logonpasswordchg:yes

It just removes the domain name or computer name from the username you get from WMI.

-Paul

Share this post


Link to post
Share on other sites
Output
  • ERROR: Description = Invalid query The command completed successfully.
     
    This is what the script shows after it is completed, but I am not sure why.....because IT WORKS! Thank you for helping I put way too much time in to that

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...