首页 > 解决方案 > 尝试使用 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

是否有可能做到这一点?如果是这样,怎么做?

标签: powershell

解决方案


推荐阅读