computing
  • 82

Solved Batch Script To Read Csv File And Output Text To File

  • 82

Hi

Im hoping someone can help me with a batch file, I need a script to read a simple csv file that contains email addresses

emailaddress
bob@company.com
john@company.com
mary@company.com
etc…

then i need for every email address thats read for the script to output to a txt file the below with the “NewPassword101” number incremented by +1 every output

Set-MsolUser -UserPrincipalName bob@company.com -StrongPasswordRequired $false
Set-MsolUserPassword bob@company.com -NewPassword “NewPassword101”
Set-MsolUser -UserPrincipalName bob@company.com -PasswordNeverExpires $true

so the out put file should look like the below?

txt file————————————

Set-MsolUser -UserPrincipalName bob@company.com -StrongPasswordRequired $false
Set-MsolUserPassword bob@company.com -NewPassword “NewPassword101”
Set-MsolUser -UserPrincipalName bob@company.com -PasswordNeverExpires $true

Set-MsolUser -UserPrincipalName john@company.com -StrongPasswordRequired $false
Set-MsolUserPassword john@company.com -NewPassword “NewPassword102”
Set-MsolUser -UserPrincipalName john@company.com -PasswordNeverExpires $true

Set-MsolUser -UserPrincipalName mary@company.com -StrongPasswordRequired $false
Set-MsolUserPassword mary@company.com -NewPassword “NewPassword103”
Set-MsolUser -UserPrincipalName mary@company.com -PasswordNeverExpires $true

end of txt file——————————————————-

Can anyone help me with this ive tried but im no coder 🙂

Share

1 Answer

  1. If your .csv file just holds one column as posted, here the script

    @echo off & setlocal EnableDelayedExpansion
    set cnt=100
    for /F "delims=" %%j in ('type "Input.csv"') do (
      set /A cnt+=1
      echo.Set-MsolUser -UserPrincipalName %%j -StrongPasswordRequired $false
      echo.Set-MsolUserPassword %%j -NewPassword "NewPassword!cnt!"
      echo.Set-MsolUser -UserPrincipalName %%j -PasswordNeverExpires $true
    ) >> "Output.txt"
    

    • 0