Run a PowerShell script with Administrator privileges through NAnt
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 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?
精彩评论