开发者

Run a PowerShell script with Administrator privileges through NAnt

开发者 https://www.devze.com 2023-02-20 11:59 出处:网络
I am currently building an automated NAnt script which will deploy SharePoint web parts.The NAnt code for this process is:-

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=" &quot;&amp; &apos;${deploysolutions.ps1}&apos; &apos;${solutionconfiguration.xml}&apos; &quot; " />
</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 &quot; -file ${deploysolutions.ps1} &quot; -ArgumentList &apos;${solutionconfiguration.xml}&apos; " />

2. <arg value=" &quot; start-process powershell -verb runas &amp; &apos;${deploysolutions.ps1}&apos; &apos;${solutionconfiguration.xml}&apos; &quot; " />

3. <arg value=" &apos; start-process powershell -verb runas &apos; " />
<arg value=" &quot;&amp; &apos;${deploysolutions.ps1}&apos; &apos;${solutionconfiguration.xml}&apos; &quot; " />

I've also tried executing admin right via the PowerShell script with no success eit开发者_运维知识库her. Does anyone have any ideas?


Cant you just wrap the call to powershell in the command runas? e.g. runas /user:adminuser powershell.exe

in your exec statement?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号