【问题标题】:Running aspnet_regiis for encryption in loop exists after first failure/success operation在第一次失败/成功操作后运行 aspnet_regiis 以循环加密
【发布时间】:2019-05-30 19:24:40
【问题描述】:

我正在编写一个 powershell 脚本,它读取一个 CSV,其中包括 Web.config/App.config 驻留应用程序的路径。脚本 simple 尝试加密配置文件。一个sn-p的代码如下:

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 在成功或失败的情况下都存在该程序。我该怎么做才能让它循环运行?

【问题讨论】:

    标签: powershell aspnet-regiis.exe


    【解决方案1】:

    通过一些打击和试验,我能够解决问题。循环停止运行的原因是:cd $directory 命令。我的猜测是,由于命令问题更改目录,因此脚本不在其当前范围内。我是新手,所以这只是我的猜测。 于是我改了一行代码:

    aspnet_regiis -pef connectionStrings "$directory" -prov CustomProvider

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多