Posted On November 3, 2021

PowerShell: Set PasswordNeverExpires on SamAccountName

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Set PasswordNeverExpires on SamAccountName

Quick 1-liner Code

$accounts=@(
    'orange',
    'apple',
    'pear',
    'dog',
    'cat',
    'dinosaur',
    'chicken',
    'cow',
    'yomama',
    'yodada'
)
$accounts|%{try{Set-ADUser -Identity $_ -PasswordNeverExpires $false;write-host "$_ : done"}catch{write-warning "$_ : error"}}

Result:

'orange': done
'apple': done
'pear': done
'dog': done
'cat': done
'dinosaur': done
'chicken': done
'cow': done
'yomama': done
'yodada': done

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Quickly Add Users into Groups on a List of Computers

$newVmNames=@( 'SERVER0001', 'SERVER0002' ) $newUsers=@( 'domain\user1' ) $groupNames='Administrators','Remote Desktop Users' $newVmNames|%{ invoke-command -computername $_ {…

PowerShell: Create, Edit User Accounts Basing on CSV File

# Create New Users: defined as names in CSV that does not exist in Existing…

PowerShell: Exchange Servers Discovery

List Exchange Servers from a non-exchange computer # Obtain a list of all on premise…
Other project: DragonCoin.com