Release Automation

Expand all | Collapse all

Powershell run as admin

  • 1.  Powershell run as admin

    Posted Mar 11, 2018 11:26 PM

    I would like to execute powershell script with administrative privileges as it requires IIS access. I have created actions using run script block and file without much luck. The user which is executing the script is already part of the local administrator's group. Any help much appreciated.



  • 2.  Re: Powershell run as admin

    Posted Mar 12, 2018 09:52 AM

    How do you execute your powershell script and what error are you getting?

     

    I'm asking because from what I know, CA Release Automation always executes command line calls etc. in an elevated shell.

     

    We're also using the Run Command Line action to call a powershell script that is used to create websites, application pools and web applications and their configuration.



  • 3.  Re: Powershell run as admin

    Posted Mar 12, 2018 08:10 PM

    Thank you Michael, PFA screenshot



  • 4.  Re: Powershell run as admin

    Posted Mar 13, 2018 02:28 AM

    does the script call work manully (same as you do it in CA-RA) on the server when you run it in an elevated shell? 

     

    looks like you're script or call itself has an error, because it's looking for the "IIS" drive

     

    here is how we start our powershell script for IIS tasks with the "run command line" action:

     

    powershell -command "&{.\CreateWeb_withARAxml.ps1 wsg_params; exit $GLOBAL:LASTEXITCODE}"

     

    As said, this works fine.



  • 5.  Re: Powershell run as admin

    Posted Mar 13, 2018 09:29 PM

    The script works absolutely fine provided I open the powershell as run as admin. This could only be achieved if I logged in to the server. The same does not work when via action in CA RA.



  • 6.  Re: Powershell run as admin

    Posted Mar 12, 2018 02:03 PM

    Hi,

    Try this,

    add your script to a bat file and execute it like this using cmd action

     

    "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -windowstyle hidden -nologo -noprofile -executionpolicy bypass -command "start-process -verb 'runas' -filepath "BAT_FILE_PATH"


  • 7.  Re: Powershell run as admin

    Posted Mar 12, 2018 08:02 PM

    Thank you mate. I did try this and it did not work due to interactive session response;

     

    Run Command Line action has failed. 
    Return value: 1. Return value is not equal to expected 0
    Std out: 
    Std err: Start-Process : This command cannot be executed due to the error: This operatio n requires an interactive window station. At line:1 char:14 + start-process <<<< -verb 'runas' -filepath E:\Code\Custom_Code\deploy ment\Environments\TST\InstallWeb.cmd + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand  
    Command line executed: cmd /c ""C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -windowstyle hidden -nologo -noprofile -executionpolicy bypass -command "start-process -verb 'runas' -filepath 



  • 8.  Re: Powershell run as admin

    Broadcom Employee
    Posted Mar 14, 2018 02:00 PM

    Hello,

     

    There is a section in the action pack's pdf regarding configuring the agent which is necessary to get the actions working properly. Have you had a look there? You can find it here, but I've pasted the text below. 

    ftp://ftp.ca.com/pub/dpm/ReleaseAutomationActions/ActionPacks/nolio-microsoft-powershell-actions/RA_Microsoft_PowerShell_ENU.pdf

     

    NOTE: The formatting seems to be off. Probably better if you view the document.

    This section provides information and procedures to configure Agents to run remotely for PowerShell actions on Windows 64-bit and 32-bit platforms. Follow these steps: Note: Both source and the target computers must be configured. Run the following command: For Windows 64-bit: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe For Windows 32-bit: C:\Windows\syswow64\WindowsPowershell\v1.0\powershell.exe Note: To run a Windows 32-bit version of PowerShellOn a Windows 64-bit system, you are required to configure Windows 32-bit PowerShell. Run the following set of commands: Set-ExecutionPolicy -ExecutionPolicy Unrestricted Enable-PSRemoting -force Set-item WSMan:\localhost\Client\TrustedHosts * -force Restart-Service WinRM -force Use one of the following examples to set up your environment to run PowerShell actions remotely: Use the Agent on the Nolio server(A) to run PowerShell commands remotely on target(B). Install the Agent on another server(C) to run PowerShell commands remotely on target(B).

     

    I hope this helps. 

     

    Kind regards,

    Gregg



  • 9.  Re: Powershell run as admin

    Broadcom Employee
    Posted Mar 14, 2018 02:05 PM

    Looking at the error you posted after running it in a Run Command Line action I'm not sure that the documented procedure will help - though it would be good to do just in case. It does seem that there is something in the powershell script that is requiring interaction with desktop - which cannot be done via the agent. When you run it manually does it prompt you for something? Things that run on agent machines must run without interacting with the desktop. If required you could run partially, get user input (in RA), finish the task based on input. But, interacting with desktop is something that we've stayed away from doing in RA because it breaks up the automation aspect if someone is sitting on a desktop waiting to do something. 



  • 10.  Re: Powershell run as admin

    Broadcom Employee
    Posted Mar 16, 2018 05:56 AM

    Hi 

     

    I would suggest to raise a normal support case so we can have a look at the script and the agents logs and configuration .

    I am sure is the script really failing on the elevated status or is this just a warning ? 

    Do you get this message also when you run it on the command prompt ? 

     

    The second part complains about cannot find drive A with name IIS which looks a bit strange 

     

    Regards

    Dirk 



  • 11.  Re: Powershell run as admin

    Posted Mar 16, 2018 06:13 AM

    the missing "iis" drive was why I wanted to see how he calls it within CA-RA, because I think what is happening is, he's not within a powershell console or doesn't import the webadmin cmdlets



  • 12.  Re: Powershell run as admin
    Best Answer

    Posted Mar 21, 2018 02:24 AM

    Hey guys, apology for the delayed reply. I noticed something - If I turn off UAC on server it works perfectly alright.

     

    The moment I turn UAC back on, issue resurfaces



  • 13.  Re: Powershell run as admin

    Broadcom Employee
    Posted Mar 28, 2018 10:40 AM

    Hi 

     

    I don;t think you can do this without disabling UAC , as the UAC will try to interact with the user to ask for the elevated rights which is not possible as the agent runs as a service.

     

    Regards

    Dirk