我正在编写一个 powershell 脚本,它读取一个 CSV,其中包括 Web.config/App.config 驻留应用程序的路径。脚本 simple 尝试加密配置文件。代码片段如下:
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
}
}
}
这里的问题是我有 5 个配置路径,但只有第一个运行并且应用程序存在。似乎aspnet_regiis
在成功或失败的情况下都存在程序。我该怎么做才能让它循环运行?