MSBuild (Cruise Control) => run PowerShell script with administrator privileges

449 Views Asked by At

I am using Cruise Control to deploy some apps to a server.

After each deploy I want to run a PowerShell that performs some actions that needs admin privileges.

I don´t manage to get that working.

I am using the following code:

<Target Name="Permisos_CAR" Condition=" '$(Permisos_CAR)'!='false' ">
    <PropertyGroup>
        <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
        <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">\\server01\d$\AppsPowerShells\Permisos.ps1</ScriptLocation>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) -executionpolicy Unrestricted -NonInteractive -file &quot;$(ScriptLocation)&quot;" ContinueOnError="True" />
</Target>

I get some errors with permissions, do you have any idea of what can I do? Thanks in advance.

Errors:

Target "Permisos_CAR": 
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy Unrestricted -NonInteractive -file "\\centdespt01\d$\AppsPowerShells\PermisosCAR.ps1"
AuthorizationManager check failed.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecord 
Exception
+ FullyQualifiedErrorId : UnauthorizedAccess

I enter on server using remote Desktop and I have set:

Set-ExecutionPolicy Unrestricted
0

There are 0 best solutions below