Score:-2

Powershell - Assign random number to AD "Telephone" Tab "IP Phone" field

cr flag

I need help with writing a PowerShell code I want to generate a Randon number (password) and assign that number to all active users in active directory. The random number will be place on the "IP Phone" field from the "Telephone" tab in AD to act as a password for secure printing

Massimo avatar
ng flag
...and you call that *secure*?!?
joeqwerty avatar
cv flag
We're not a script writing service. What have you tried and what were your results?
djdomi avatar
za flag
chatgpt will for sure write it, but using this site requires at least the knowledge of [ask]
Davidw avatar
in flag
Voted to close for unreasonable IT practices.
Jan avatar
ru flag
Jan
Very bad idea. That field is not protected by any means and can be read by everyone
Score:0
cn flag

Generate a random number with PowerShell is easy:

$RandomNumber = Get-Random -Minimum 1 -Maximum 10

Then you will need to add them in the field with set-AdUser

https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps

Score:0
cr flag

#Get a list of all employees. $searchlist = Get-ADOrganizationalUnit -Filter * -SearchBase "OU=VNA Users,OU=VNA,DC=vnatc,DC=local" | Select-Object -ExpandProperty DistinguishedName $employeelist = foreach($ou in $searchlist){ get-aduser -Filter * -SearchBase $ou | Select-Object -ExpandProperty SamAccountName }

#####Assigning the Password to the Employee in the Employee List##### foreach($employee in $employeelist){ $password = Get-Random -Minimum 100000 -Maximum 999999 $password Set-ADUser -Identity $employee -Replace @{ipPhone=$password} -WhatIf }

This is what I have written so far. I need to append this to a CSV file, then assign a passcode to each user. Hope to get some feedback.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.