Jump to content

Recommended Posts

Posted

I need to reset the password for a number of users in different OU's. I have a powershell script which does the same password for all in an ou however i need a different password for each user. The password also needs to be simple but different for each user e.g. user 1 gets dog whilst user 2 gets cat. I have created a script to get these passwords but have no way of reseting the users password in AD.

 

Prefer a GUI if possible

Posted

Ok script currently is

 

DSQUERY user "OU= [intake Year],OU=Students,OU=User Resources,OU=[school Name],OU=[Academy],DC=[DC Name],DC=[],DC=[]" -limit 0 | DSMOD user -pwd Password1

 

What should i remove and not sure best way to add example 8 to it. So I want 1 kid to say get a password called Redcat8 whilst another to get Bluedog2 and so on.

Posted

This is not tested and probably has a couple syntax errors, but should be a good start.

 

$users = Get-ADUser -SearchScope subtree -SearchBase "OU= [intake Year],OU=Students,OU=User Resources,OU=[school Name],OU=[Academy],DC=[DC Name],DC=[],DC=[]" -Filter * 
foreach ($user in $users){
$password = Get-Random -InputObject "cat", "dog", "red" 
$password = ConvertTo-SecureString  $password -AsPlainText -Force
Set-ADAccountPassword -Identity $user -NewPassword $password
$password = $null

}

  • Thanks 1
Posted
Do you still need a hand with this? I can hopefully whip something up for you that would do it.

 

Just going to use the GUI and have same type of password but random digit and letter added. If you have any other way then that would be good.

Posted (edited)

It's not a GUI and I only just noticed that @ADMaster already did this but here is what I have:

[color=#d4d4d4][font=Monaco][color=#dcdcaa]Import-Module [/color][color=#d4d4d4]ActiveDirectory[/color]

[color=#569cd6]$[/color][color=#9cdcfe]importPath[/color][color=#d4d4d4]=[/color][color=#ce9178]"C:\User Scripts\Scripts\Create User with Random Password\password.csv"[/color]

[color=#569cd6]$[/color][color=#9cdcfe]ou[/color][color=#d4d4d4]=[/color][color=#608b4e]#ou path here[/color]

[color=#569cd6]$[/color][color=#9cdcfe]users[/color][color=#d4d4d4]=[/color][color=#dcdcaa]Get-ADUser[/color][color=#d4d4d4]-[/color][color=#d4d4d4]SearchBase [/color][color=#569cd6]$[/color][color=#9cdcfe]ou[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Filter [/color][color=#d4d4d4]*[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Properties [/color][color=#d4d4d4]*[/color][color=#d4d4d4]-[/color][color=#d4d4d4]ResultSetSize [/color][color=#b5cea8]5000[/color][color=#d4d4d4]|[/color][color=#dcdcaa]Select-Object[/color][color=#d4d4d4] GivenName[/color][color=#d4d4d4],[/color][color=#d4d4d4] Surname[/color][color=#d4d4d4],[/color][color=#d4d4d4] SamAccountName[/color][color=#d4d4d4],[/color][color=#d4d4d4] Password[/color]

[color=#569cd6]$[/color][color=#9cdcfe]passwordFile[/color][color=#d4d4d4]=[/color][color=#dcdcaa]Get-Content[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Path [/color][color=#569cd6]$[/color][color=#9cdcfe]importPath[/color][color=#d4d4d4]|[/color][color=#dcdcaa]ConvertFrom-Csv[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Header [/color][color=#d4d4d4]Password[/color]

[color=#c586c0]foreach[/color][color=#569cd6]($[/color][color=#9cdcfe]user[/color][color=#c586c0]in[/color][color=#569cd6]$[/color][color=#9cdcfe]users[/color][color=#569cd6])[/color][color=#d4d4d4]{[/color]
 [color=#569cd6]$[/color][color=#9cdcfe]password[/color][color=#d4d4d4]=[/color][color=#569cd6]$[/color][color=#9cdcfe]passwordFile[/color][color=#dcdcaa].Password[/color]
 [color=#569cd6]$[/color][color=#9cdcfe]randomPassword[/color][color=#d4d4d4]=[/color][color=#dcdcaa]Get-Random[/color][color=#d4d4d4]-[/color][color=#d4d4d4]InputObject [/color][color=#569cd6]$[/color][color=#9cdcfe]password[/color]
 [color=#dcdcaa]Write-Host[/color][color=#569cd6]$[/color][color=#9cdcfe]user[/color][color=#569cd6]$[/color][color=#9cdcfe]randompassword #You could log this line or export to CSV to get a list of the passwords just make sure it's here before it converts to secure string[/color]
 [color=#569cd6]$[/color][color=#9cdcfe]randomPassword[/color][color=#d4d4d4]=[/color][color=#dcdcaa]ConvertTo-SecureString[/color][color=#569cd6]$[/color][color=#9cdcfe]randomPassword[/color][color=#d4d4d4]-[/color][color=#d4d4d4]AsPlainText [/color][color=#d4d4d4]-[/color][color=#d4d4d4]Force[/color]
 [color=#608b4e]Set-ADAccountPassword -Identity $user -NewPassword $randomPassword[/color]

[color=#d4d4d4]}[/color]

[/font][/color]

All you have to do is make a CSV file with a header of "Password" and then a list of your chosen passwords that it would randomly select, it will then choose once at random and apply it to that account.

Edited by ShellfishClive
  • Thanks 1
Posted
It's not a GUI and I only just noticed that @ADMaster already did this but here is what I have:

[color=#d4d4d4][font=Monaco][color=#dcdcaa]Import-Module [/color][color=#d4d4d4]ActiveDirectory[/color]

[color=#569cd6]$[/color][color=#9cdcfe]importPath[/color][color=#d4d4d4]=[/color][color=#ce9178]"C:\User Scripts\Scripts\Create User with Random Password\password.csv"[/color]

[color=#569cd6]$[/color][color=#9cdcfe]ou[/color][color=#d4d4d4]=[/color][color=#608b4e]#ou path here[/color]

[color=#569cd6]$[/color][color=#9cdcfe]users[/color][color=#d4d4d4]=[/color][color=#dcdcaa]Get-ADUser[/color][color=#d4d4d4]-[/color][color=#d4d4d4]SearchBase [/color][color=#569cd6]$[/color][color=#9cdcfe]ou[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Filter [/color][color=#d4d4d4]*[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Properties [/color][color=#d4d4d4]*[/color][color=#d4d4d4]-[/color][color=#d4d4d4]ResultSetSize [/color][color=#b5cea8]5000[/color][color=#d4d4d4]|[/color][color=#dcdcaa]Select-Object[/color][color=#d4d4d4] GivenName[/color][color=#d4d4d4],[/color][color=#d4d4d4] Surname[/color][color=#d4d4d4],[/color][color=#d4d4d4] SamAccountName[/color][color=#d4d4d4],[/color][color=#d4d4d4] Password[/color]

[color=#569cd6]$[/color][color=#9cdcfe]passwordFile[/color][color=#d4d4d4]=[/color][color=#dcdcaa]Get-Content[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Path [/color][color=#569cd6]$[/color][color=#9cdcfe]importPath[/color][color=#d4d4d4]|[/color][color=#dcdcaa]ConvertFrom-Csv[/color][color=#d4d4d4]-[/color][color=#d4d4d4]Header [/color][color=#d4d4d4]Password[/color]

[color=#c586c0]foreach[/color][color=#569cd6]($[/color][color=#9cdcfe]user[/color][color=#c586c0]in[/color][color=#569cd6]$[/color][color=#9cdcfe]users[/color][color=#569cd6])[/color][color=#d4d4d4]{[/color]
 [color=#569cd6]$[/color][color=#9cdcfe]password[/color][color=#d4d4d4]=[/color][color=#569cd6]$[/color][color=#9cdcfe]passwordFile[/color][color=#dcdcaa].Password[/color]
 [color=#569cd6]$[/color][color=#9cdcfe]randomPassword[/color][color=#d4d4d4]=[/color][color=#dcdcaa]Get-Random[/color][color=#d4d4d4]-[/color][color=#d4d4d4]InputObject [/color][color=#569cd6]$[/color][color=#9cdcfe]password[/color]
 [color=#dcdcaa]Write-Host[/color][color=#569cd6]$[/color][color=#9cdcfe]user[/color][color=#569cd6]$[/color][color=#9cdcfe]randompassword #You could log this line or export to CSV to get a list of the passwords just make sure it's here before it converts to secure string[/color]
 [color=#569cd6]$[/color][color=#9cdcfe]randomPassword[/color][color=#d4d4d4]=[/color][color=#dcdcaa]ConvertTo-SecureString[/color][color=#569cd6]$[/color][color=#9cdcfe]randomPassword[/color][color=#d4d4d4]-[/color][color=#d4d4d4]AsPlainText [/color][color=#d4d4d4]-[/color][color=#d4d4d4]Force[/color]
 [color=#608b4e]Set-ADAccountPassword -Identity $user -NewPassword $randomPassword[/color]

[color=#d4d4d4]}[/color]
[/font][/color]

All you have to do is make a CSV file with a header of "Password" and then a list of your chosen passwords that it would randomly select, it will then choose once at random and apply it to that account.

 

Thanks for this but don't quite get the script! I actually hate powershell!!!

Posted

I'll try break it down for you:

 

1. $importPath is the location of your custom csv file. The one I created had "Password" written in the first cell and then a random list of passwords in each cell below. Bluedog1, bluedog2, redcat3 etc. (Ordering doesn't matter)

2. $ou is the OU that contains the users that you want to change the passwords for. E.g. $ou = "OU=TestOU,OU=Staff,OU=Users,OU=School Name,DC=Domain,DC=org ,DC=uk"

3. $users this gets the users from the OU that you have pointed to above, so any users in the OU "TestOU" will have their password reset.

4. $PasswordFile will get the lists of passwords from the CSV file in a list.

 

The Foreach loop says that for every User in the OU I want to you do whatever is inbetween {} these brackets. Once you have done this move onto the next user, then the next user until no users are left.

 

$password just grabs the passwords from the file and makes it easier to use in the script.

 

$randompassword tells the scripts to get a random password from the $password varaible (which is just the list of passwords in the .csv)

 

Write-Host just shows you what the password will be for that user.

 

The next line makes the password secure in order for it to be used as a password.

 

Set-ADAccountPassword is what actually does the setting of the password in AD.

 

I am awful at explaining things but hopefully that helps even just a little.

Posted
Code tags - squarebracketCODEsquarebracketCONTENTsquarebracket/CODEsquarebracket [emoji6]

 

yeah my post 4 uses code tags but its plain compared to post 7.

Posted
yeah my post 4 uses code tags but its plain compared to post 7.
In addition to what @3s-gtech mentioned, you also need to use the "Enhanced" message editor interface (under "General Settings" in your EduGeek profile) and a text editor like VSCode that supports copying the syntax highlighted text to the clipboard.

 

KqptFL.png

 

[color=#00008B][font=Consolas]$[/font][/color][color=#FF4500][font=Consolas]users[/font][/color][color=#A9A9A9][font=Consolas]=[/font][/color][color=#0000FF][font=Consolas]Get-ADUser[/font][/color][color=#A9A9A9][font=Consolas]-[/font][/color][color=#333333][font=Consolas]SearchScope subtree [/font][/color][color=#A9A9A9][font=Consolas]-[/font][/color][color=#333333][font=Consolas]SearchBase [/font][/color][color=#8B0000][font=Consolas]"OU= [intake Year],OU=Students,OU=User Resources,OU=[school Name],OU=[Academy],DC=[DC Name],DC=[],DC=[]"[/font][/color][color=#A9A9A9][font=Consolas]-[/font][/color][color=#333333][font=Consolas]Filter [/font][/color][color=#A9A9A9][font=Consolas]*[/font][/color][color=#333333][font=Consolas]

[color=#00008b]foreach[/color] [color=#00008b]($[/color][color=#ff4500]user[/color] [color=#00008b]in[/color] [color=#00008b]$[/color][color=#ff4500]users[/color][color=#00008b])[/color] {
   [color=#00008b]$[/color][color=#ff4500]password[/color] [color=#a9a9a9]=[/color] [color=#0000ff]Get-Random[/color] [color=#a9a9a9]-[/color]InputObject [color=#8b0000]"cat"[/color][color=#a9a9a9],[/color] [color=#8b0000]"dog"[/color][color=#a9a9a9],[/color] [color=#8b0000]"red"[/color]
   [color=#00008b]$[/color][color=#ff4500]password[/color] [color=#a9a9a9]=[/color] [color=#0000ff]ConvertTo-SecureString[/color]  [color=#00008b]$[/color][color=#ff4500]password[/color] [color=#a9a9a9]-[/color]AsPlainText [color=#a9a9a9]-[/color]Force
   [color=#0000ff]Set-ADAccountPassword[/color] [color=#a9a9a9]-[/color]Identity [color=#00008b]$[/color][color=#ff4500]user[/color] [color=#a9a9a9]-[/color]NewPassword [color=#00008b]$[/color][color=#ff4500]password[/color]
   [color=#00008b]$[/color][color=#ff4500]password[/color] [color=#a9a9a9]=[/color] [color=#00008b]$[/color][color=#008080]null[/color]
[/font][/color]
[color=#333333][font=Consolas]}[/font][/color]

  • Thanks 1
Posted

I am using the enhanced editor, but I copy from the built in powershell ise.

 

Its too late to edit my previous post so I'll install vs code and try next time.

 

Thanks,

Posted (edited)

Think you have a number of good options available here for you to achieve what you need to, however if you find you need another option ping me.

I have an old skool cmd line script that bulk resets to random passwords by using a csv. Never really had the need to use it so never adapted it. Basically Does the same as Ps script but not as clean but just as effective

Thanks

Edited by dapaulio
Posted (edited)
I use a dark theme so it doesn't display nicely on a white site.

Me too. I use the Monokai Dimmed dark VSCode theme.

 

It's easy to remove the background colour with a bit of PowerShell. :)

[color=#676867]([/color][color=#9872a2]Get-Clipboard[/color] [color=#676867]-[/color]TextFormatType Html[color=#676867])[/color] [color=#676867]-replace[/color] [color=#9aa83a]"(?smi)background-color: #([1-9a-fA-F]{3}|[1-9a-fA-F]{6});"[/color] [color=#676867]|[/color] [color=#9872a2]Set-Clipboard[/color] [color=#676867]-[/color]AsHtml

Like you say, when the background colour is removed some of the text is harder to read on a lighter background, although I noticed it looks slightly better when pasting it into Microsoft Word compared to this forum.

 

I might just stick with the plain black code myself (or temporarily switch to a lighter theme).

Edited by Arthur
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...