PoshCode Archive  Artifact [d3f3115af6]

Artifact d3f3115af6057749812aaf7007873f61f9f1aea475176a8bf824d34d7107a453:

  • File Set-ADUserRandomPassword.ps1 — part of check-in [2ad48ab0fd] at 2018-06-10 12:56:48 on branch trunk — This script are used to set a random password for Active Directory users in a specified Organizational Unit. It stores the results in a csv-file. (user: Jan Egil Ring size: 2543)

# encoding: ascii
# api: powershell
# title: Set-ADUserRandomPassword
# description: This script are used to set a random password for Active Directory users in a specified Organizational Unit. It stores the results in a csv-file.
# version: 1.0
# type: script
# author: Jan Egil Ring
# license: CC0
# x-poshcode-id: 1285
# x-archived: 2016-06-01T12:46:13
# x-published: 2010-08-22T14:39:00
#
# The background for this script is a school domain needing to set random passwords for new users, and exporting the passwords to a csv-file to let the teachers disribute the first-time passwords.
#
###########################################################################"
#
# NAME: Set-ADUserRandomPassword.ps1
#
# AUTHOR: Jan Egil Ring
# EMAIL: jan.egil.ring@powershell.no
#
# COMMENT: This script are used to set a random password for Active Directory users in a specified Organizational Unit. It stores the results in a csv-file.
#          The background for this script is a school domain needing to set random passwords for new users, and exporting the passwords to a csv-#          #          file to let the teachers disribute the first-time passwords.
#
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 22.08.2009 - Initial release
#
###########################################################################"

#Requires: Quest.ActiveRoles.ADManagement

#Creating system.random object used to generate random numbers
$random = New-Object System.Random
#Creating an array to store user information in
$CSV = @()
#Get users
Get-QADUser -SearchRoot "domain.local/MyUserOU" -SizeLimit 0 | ForEach-Object {
#Generate a random password for each user
$password = "pwd"+($random.Next(1000,9999))
#Set the password for each user
Set-QADUser $_ -UserPassword $password
#Select what user information we want to export to the csv-file and storing it in a variable
$exportdata = Get-QADUser $_ | Select-Object name,samaccountname,company,department
#Add the password as a member to $exportdata
Add-Member -InputObject $exportdata -MemberType NoteProperty -Name Password -Value $password
#Add the user information to the $CSV array
$CSV += $exportdata
}
#Exporting all users to the csv-file
$CSV | Export-Csv -Path "C:\export\passwordlist.csv" -Encoding unicode -NoTypeInformation