通过 NAnt 以管理员权限运行 PowerShell 脚本
我目前正在构建一个自动化 NAnt 脚本,它将部署 SharePoint Web 部件。此过程的 NAnt 代码为:-
<echo message="Deploying Solutions" />
<exec failonerror="true" program="${powershell.exe}">
<arg value="-noprofile" />
<arg value="-nologo" />
<arg value="-noninteractive" />
<arg value="-command" />
<arg value=" "& '${deploysolutions.ps1}' '${solutionconfiguration.xml}' " " />
</exec>
其中 ${deploysolutions.ps1} 是要运行的脚本,${solutionconfiguration.xml} 是要传递给脚本的参数。
在我的本地计算机上运行时效果很好。当我尝试通过 SharePoint 开发服务器上的巡航控制运行此程序时,我遇到了权限错误。我已验证所使用的凭据具有必要的权限。我在构建日志中看到的错误是:-
[exec] Deploy-Solution : Unable to add solution MyWebParts.wsp
这是我在 PowerShell 脚本中抛出的错误
try
{
Write-Host "Adding solution $name"
Add-SPSolution -LiteralPath $path -ErrorAction Stop
Start-Sleep -Seconds 60
# as above
}
catch
{
Write-Error "Unable to add solution $name"
throw "Could not add solution $name"
}
但是,当以管理员身份运行时通过 PowerShell 控制台运行相同的命令时,凭据没有问题。
有没有办法告诉 NAnt 调用以管理员身份运行 PowerShell?我尝试了以下操作,但没有成功:-
1. <arg value="Start-Process powershell -verb runas -FilePath " -file ${deploysolutions.ps1} " -ArgumentList '${solutionconfiguration.xml}' " />
2. <arg value=" " start-process powershell -verb runas & '${deploysolutions.ps1}' '${solutionconfiguration.xml}' " " />
3. <arg value=" ' start-process powershell -verb runas ' " />
<arg value=" "& '${deploysolutions.ps1}' '${solutionconfiguration.xml}' " " />
我还尝试通过 PowerShell 脚本直接执行管理,但也没有成功。有人有什么想法吗?
I am currently building an automated NAnt script which will deploy SharePoint web parts. The NAnt code for this process is:-
<echo message="Deploying Solutions" />
<exec failonerror="true" program="${powershell.exe}">
<arg value="-noprofile" />
<arg value="-nologo" />
<arg value="-noninteractive" />
<arg value="-command" />
<arg value=" "& '${deploysolutions.ps1}' '${solutionconfiguration.xml}' " " />
</exec>
where ${deploysolutions.ps1} is the script to run and ${solutionconfiguration.xml} is an argument to be passed to the script.
This works fine when running on my local machine. When I try to run this through cruise control on our SharePoint development server I run into permission errors. I have verified that the credentials being used have the requisiste permisisons. The error I am seeing in the build log is:-
[exec] Deploy-Solution : Unable to add solution MyWebParts.wsp
which is the error I throw within the PowerShell script
try
{
Write-Host "Adding solution $name"
Add-SPSolution -LiteralPath $path -ErrorAction Stop
Start-Sleep -Seconds 60
# as above
}
catch
{
Write-Error "Unable to add solution $name"
throw "Could not add solution $name"
}
However, the credentials are fine when runing the same commands through the PowerShell Console when run as Administrator.
Is there a way I can tell the NAnt call to run PowerShell as Administrator? I've tried the following with no success:-
1. <arg value="Start-Process powershell -verb runas -FilePath " -file ${deploysolutions.ps1} " -ArgumentList '${solutionconfiguration.xml}' " />
2. <arg value=" " start-process powershell -verb runas & '${deploysolutions.ps1}' '${solutionconfiguration.xml}' " " />
3. <arg value=" ' start-process powershell -verb runas ' " />
<arg value=" "& '${deploysolutions.ps1}' '${solutionconfiguration.xml}' " " />
I've also tried executing admin right via the PowerShell script with no success either. Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道你不能将对 powershell 的调用包装在命令 runas 中吗?
runas /user:adminuser powershell.exe ?
例如,在您的 exec 语句中
Cant you just wrap the call to powershell in the command runas?
e.g. runas /user:adminuser powershell.exe
in your exec statement?