John Savill'ss FAQs on IT Pro Today Hero

Savill's FAQs: Bulk changing passwords in Active Directory

Three times a week, John Savill tackles your most pressing IT questions. Today: Learn about changing passwords in bulk for an Active Directory Organizational Unit; how to store arrays of objects in PowerShell long term; and expanding storage to Azure for future use.

Three times a week (Monday/Wednesday/Friday), John Savill tackles your most pressing IT questions.

Read through the FAQ archives, or send him your questions via email.

Today: We look at bulk changing passwords in an Organizational Unit, how to store arrays of objects long term, and then expanding that storage to Azure.


Q. How can I bulk update passwords for users in a certain OU?

A. One of the great properties of PowerShell is the ability to pipe objects between commands. To change the password of all accounts in a certain OU requires listing the users in the OU, then piping those to the cmdlet to change the password. For example:

$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
Get-ADUser -SearchBase <DN of the OU> -Filter * | Set-ADAccountPassword -NewPassword $securePassword -Reset


Q. I have an array of objects I want to store and easily read back. What's the best way to store in PowerShell?

A. I'm not sure if there is a best way, but there is a format that can be universally understood. JSON is natively supported with PowerShell. Once you have the data in JSON format, you could then output to a file which could be read to a file share if required. For example:

$DataArray | ConvertTo-Json | Out-File file.json

It does not matter what the array of objects is, after being sent to ConvertTo-Json it can easily be output to a file. Likewise it can easily be read back. For example:

$DataArray = Get-Content file.json | convertfrom-json


Q. What is a simple way to store data in Azure to easily use from PowerShell?

A. There are many options here, as Azure has a huge range of services. You could consider:

  • Tables via Azure Storage Account or CosmosDB
  • Documents via CosmosDB
  • Databases in Azure SQL Database or CosmosDB

If I have data and want to easily use from many scripts, I'll store it as a JSON file and save to an Azure Files share. That way, I don't need any special code to handle the storage and instead can just leverage the share and the JSON cmdlets.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish