I am writing a powershell script which reads a CSV which includes path where Web.config/App.config resides applications. The script simple tries to encrypt the configuration files. A snippet of the code is as:
foreach ($config in $configs) {
$rootPath = Get-Location
$directory = Join-Path -Path $rootPath -ChildPath $config.GetPath()
if (Test-Path -Path $directory) {
$configPath = Join-Path $directory -ChildPath $config.GetOriginalConfig()
if (![System.IO.File]::Exists($configPath)) {
Write-Host "$configPath was not found."
return
}
# A set of helper codes
Try {
cd $directory
# Invoke-Command $moveToDirectory
aspnet_regiis -pef connectionStrings . -prov CustomProvider
}
Catch {
Write-Host $$_.Exception.Message
}
}
}
The problem here is that I have 5 configuration path but only the first one runs and the application exists. It seems that aspnet_regiis
exists the program in both success or failure case. What can I do to make it run in a loop?