- johnnyonetime
- Apr 2, 2010
-
|
I have an OU of users that I would like to set the passwords to never expire using Powershell. There are a LOT of google results on how to do this but I have had zero luck getting the script to achieve this. Can a powershell guru take a look and tell me what's wrong with this?
code:$Never_Expire=0x10000
$objou = New-Object System.DirectoryServices.DirectoryEntry("LDAP://ou=MyUsers,dc=example,dc=com")
$objSearcher = New-Object System.DirectoryServices.directorySearcher
$objsearcher.searchroot = $objou
$objsearcher.filter = '(&(objectCategory=User)(Objectclass=user)(!isCriticalSystemObject=*))'
$objsearcher.searchscope = "subtree"
$results = $objsearcher.findall()
foreach ($result in $results) {
$user = [adsi]$result.path
$value = $user.useraccountcontrol.item(0)
$value = $value -bor $Never_Expire
$user.useraccountcontrol = $value
$user.name
$user.setinfo()
}
Bonus Question! I'm a new powershell user and can already tell it is awesome. What is the easiest way to have a nice little repository of scripts I can pull up in Powershell for day-to-day activities?
|
#
¿
Oct 11, 2011 22:20
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
Apr 30, 2024 20:04
|
|