Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Saturday, November 24, 2018

Powershell Script to reset password in multiple configuration files.

Hi folks,

              Our project is having separate SSIS development team and we DBA team. SSIS team develops packages and gives them us to deploy on database server in our support. Most of the packages we deploy with files system methods.
              Sometimes on customer request development team needs to make changes in packages. So they request us to provide current packages(.dtsx files and respective .config files). In this we locate package locations and provide them. But as per project policy, no one should share files containing username password where configuration files contain connection strings i.e username and passwords in them. So we copy packages, put ***** in place of password and share same with development team.
              This is easy to do manually if there are 3 or 4 packages, but sometimes we get request in which development team asks for multiple packages or all packages. In this case its difficult and hectic 😩  to open each config file and replace password with *****.
              So we have my favorite 😍 and powerful tool in arsenal - PowerShell !!! You can do anything and automate everything on your system with the help of PowerShell except turn on your PC which is off now 😜. To perform this activity for 30 packages manually and correctly anyone will require at least 30 mins. But using PowerShell it will take 5 min max.
              We have developed small PowerShell script which performs this big activity in few seconds.
Find below for same. Also you can use same script if want reset password which is recently changes.
Or you can use it to replace particular word in multiple text files, words files etc.
                Try it and let me know feedback or suggestions in comment..............

#-----------------------------------------------------------------------------------------------------------------



$configFiles = Get-ChildItem “N:\Packages\” -r -include *.dtsconfig

# Change location here before execution

foreach ($file in $configFiles)

{

    (Get-Content $file.PSPath) |

    Foreach-Object { $_ -replace [regex]::Escape('CurrentPassword'), 'NewPassword' } |

    Set-Content $file.PSPath

}


#-----------------------------------------------------------------------------------------------------------------

# .dtsconfig - you can replace it with .txt, .csv etc as per requirement
# CurrentPassword - password/word which you want to replace.
# NewPassword - new password/word with which you want to replace