?
Solved

Powershell-script: Modify of local(non-AD)-user accounts

Posted on 2010-01-12
4
Medium Priority
?
2,195 Views
Last Modified: 2012-05-08
I am looking for an [adsi]("WinNT://./$strUser, user") --> psbase.invoke("?","?") command for enabling 'Password never expires' and 'User cannot change password'.

I have succesfully build a script that changes passwords according to an CSV-file - see attached script, and now imagine adding two lines of code doing the job.

Help is greatly appreciated...
{
    $ImportUserListPath = "E:\Anders\JmaWebUserNamesPasswords.csv"

    $users = Import-Csv $ImportUserListPath
    Foreach ($user in $users)
    {

    $strUser = $User.username
    $strPWD = $User.Password
    $strUser
    $LocalUser =[adsi]("WinNT://./$strUser, user")
    $LocalUser.psbase.invoke("SetPassword", $strPWD)
    # Password never expires: $LocalUser.psbase.invoke( ??? )
    # User cannot change password: $LocalUser.psbase.invoke( ??? )
    }
}

setPasswordFromCSV

Open in new window

0
Comment
Question by:jmateknik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:KingR
ID: 26293539
QAD can only be used for AD accounts, not local.

I haven't tried this myself, but both these entries are userflags so you should be able to set the value of the userflag for the account. A good list of the values (which you simply add together) is at http://www.motobit.com/help/usrmgr/cl16.htm
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 26293614

Just like this...

Chris
# Constant values for these user flags
$UFCannotChangePwd = 64
$UFPwdNeverExpires = 65536


{
    $ImportUserListPath = "E:\Anders\JmaWebUserNamesPasswords.csv"

    $users = Import-Csv $ImportUserListPath
    Foreach ($user in $users)
    {

    $strUser = $User.username
    $strPWD = $User.Password
    $strUser
    $LocalUser =[adsi]("WinNT://./$strUser, user")
    $LocalUser.psbase.invoke("SetPassword", $strPWD)
    # Bitwise OR to add the existing value with the new flag
    $LocalUser.Put("UserFlags", $LocalUser.Get("UserFlags") -BOr $UFCannotChangePwd)
    $LocalUser.Put("UserFlags", $LocalUser.Get("UserFlags") -BOr $UFPwdNeverExpires)
    # Commit the change
    $LocalUser.SetInfo()
    }
}

setPasswordFromCSV

Open in new window

0
 
LVL 1

Author Closing Comment

by:jmateknik
ID: 31676098
I Humbly thanks for the joy that this script has spread - exellent! :)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question