powershell - 尝试使用 aspnet_regiis 远程运行 Powershell。错误:对象已存在
问题描述
我正在尝试使用 Powershell 脚本在远程计算机上运行 aspnet_regiis。
我做了很多实验。
如果我直接在目标机器上运行它,它可以正常工作。这些是步骤。我以管理员身份运行 Powershell:
Enter-PSSession -ComputerName "name"
这让我进去了。
然后我运行 Set-Location 以到达正确的路径。
然后我运行我的 ps1 文件。
.\EncryptConfig.ps1
它做了一些初步的事情。如果存在,则删除 web.config。将 App.Config 文件重命名为 web.config。这一切都好吗。然后它尝试运行 aspnet_regiis:
$rpath="$Env:Windir\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef `"connectionStrings`" `"$TargetDir`""
invoke-expression $rpath
这是发生错误的地方。(未能使用提供者“RsaProtectedConfigurationProvider”对“connectionStrings”部分进行加密。来自提供者的错误消息:对象已存在。)
我检查了我是否拥有正确的凭据:
write-output ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
True
是否有可能做到这一点?如果是这样,怎么做?
解决方案
推荐阅读
- javascript - navigator.geolocation.getCurrentPosition 大约需要 30 - 40 秒才能获得 js 中的位置
- json - 无法将 sed 输出存储到变量
- node.js - process.env.PORT 未定义(在 LinuxCloud 环境中)
- javascript - HtmlAgilityPack,从特定页面加载所有评论,包括卸载评论
- r - 条件值过滤
- mysql - 为每行选择 x 天的 AVG
- sql - 不支持 Access SQL 连接表达式
- java - 无法通过代理进行隧道传输。代理返回“需要 HTTP/1.1 407 代理身份验证”
- reactjs - 如何防止 CreateReactApp 编译因 lint 错误而停止?
- openmdao - Openmdao - 优化时并行计算有限差分