executePowershell()
NOTE When running Powershell commands from agent procedures as System, the Execution Policy for LocalMachine context is automatically set to "Unrestricted". If you do not wish to leave this setting in place, add a statement at the end of the procedure to set it back to the desired value using Set-ExecutionPolicy command.
Executes a powershell script, including:
- a Powershell
.PS1
file - a Powershell command with special arguments
- a combination of both
Operating systems supported: Windows XP SP3+/Server 2008 with Powershell add-on, Windows 7, Windows Server 2008 or later
There are five variants of this command available.
- executePowershell() - Executes a powershell file, or command with arguments, or both. When running this command on either a 32bit or 64bit machine, no system credential or user credential is provided.
- executePowerShell32BitSystem - Executes a powershell file, or command with arguments, or both, as a 32 bit system command.
- executePowerShell32BitUser - Executes a powershell file, or command with arguments, or both, as a 32 bit user command.
- executePowerShell64BitSystem - Executes a powershell file, or command with arguments, or both, as a 64 bit system command.
- executePowerShell64BitUser - Executes a powershell file, or command with arguments, or both, as a 64 bit user command.
System and user commands:
- System - If asystem command is run, execution is restricted to the agent's system level access.
- User - If a usercommand is selected, then a credential must be specified by running either the impersonateUser() or useCredential() command before this command.
NOTE To avoid risk of privilege escalation attacks, scripts and files which run under System context, or as an Administrator level user, should be executed from a folder with locked down ACL permissions. The VSA agent provides a default folder called "System", under the Agent Working Directory, which is intended for this use. It can be stored as a variable by selecting "Secure Agent Working Directory Path" from the getVariable() command.
Example
executePowershellCommand64BitSystem("#ps_service_script#, "#servicename#", false, "All Operating Systems", "All Windows Operating Systems, "Halt on Fail")