Set-MsolUserPassword with a csv file

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Byron Grogan Byron Grogan 1 year, 11 months ago.

  • Author
    Posts
  • #21614
    Profile photo of Byron Grogan
    Byron Grogan
    Participant

    I am wondering whether anyone has attempted to set multiple MSOL passwords using the Set-MsolUserPassword cmdlet with a csv file?

  • #21616
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Yes.

  • #21618
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Aside from not liking to put plain-text passwords into something like a CSV file, this should be pretty easy. Assuming you had a CSV file with Username and Password columns, the standard boilerplate PowerShell code could look something like this:

    Import-Csv .\yourCsvFile.csv |
    ForEach-Object {
        Do-Something -Username $_.Username -Password $_.Password
    }
    

    I don't know what Set-MsolUserPassword's parameters are, off the top of my head, but you get the idea. You might need to convert the string passwords into SecureString objects first, using ConvertTo-SecureString -AsPlainText -Force , and so on.

  • #21620
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You'd be after -NewPassword and -UserPrincipalName, both of which actually accept pipeline input ByPropertyName. So if the CSV had columns named "NewPassword" and "UserPrincipalName"...

    Import-CSV Data.csv | Set-MsolUserPassword

    Usually works. I usually end up using -TenantId as well, of course.

  • #21622
    Profile photo of Byron Grogan
    Byron Grogan
    Participant

    This worked for me

    Import-Csv File.csv | ForEach-Object { Set-MsolUserPassword -ForceChangePassword $false -UserPrincipalName $_.UserPrincipalName -NewPassword $_.NewPassword }

    🙂

You must be logged in to reply to this topic.