- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.
06-25-2019 07:16 PM
The attached PowerShell script is a non-CyberArk script we use to remotely execute the vf_agent commands. As an example, we use this to execute -SupportInfo against a target machine, then download the zip file to your local Download directory with a prefix of CyberArk.MachineName for tracking.
This has been extremely useful to us as we cannot always pull the remote support file from agents within the console, and we do not have the ability to contact the individuals with the agents with issues. The script also allows remote execution of all the other command line parameters of the vf_agent.. so it has been useful for us to remotely stop / start the agent etc remotely from command line.
You can see all the options with: Get-Help Invoke-CyberarkAgentAction
To execute this- open PowerShell as an Administrator...
**Pre-Req: You need admin access to spawn processes on the local machine**
1) Your admin ID folder must exist on the remote machine in C:\Users. To create that execute the following within Powershell against the target machine:
2) Import the script into PS using import-module command:
3) Execute "Set-ExecutionPolicy bypass" (if you have not already)
4) Execute the action.
For example:
This executes the -SupportInfo command then sends the zip file to the download folder on your admin PC:
C:\Users\MyAdminUserID\Downloads\
Example:
CyberArk.USER12345.2019.06.25.05.22.36 .zip
Notes:
If your admin folder does not exist on the remote machine, the command for -SupportInfo will will cause the script to not complete. It should be easy to change the output of the support file to windows temp and not require the remote user folder, we just have not got around to that yet.
Enjoy!
-TT
<#
Wrapper for CyberArk agent commands, designed to run on remote endpoints using WMI
TODO:
* Test piping
* Passing multiple targets
* Test all parameters
https://cyberarkdocu.azurewebsites.net/Product-Doc/OnlineHelp/EPM/Latest/en/Content/EPM_PET/Agent%20Commands.htm?Highlight=vf_agent
Invoke-CyberarkAgentAction -ComputerName <target> -Action SuspendPolicies -Token "j2l3k4hl23h4kj2h34jk23h4lk23"
Invoke-CyberarkAgentAction -ComputerName <target> -Action SuspendPolicies
Invoke-CyberarkAgentAction -ComputerName <target> -Action ResumePolicies
Invoke-CyberarkAgentAction -ComputerName <target> -Action RequestPolicies
Invoke-CyberarkAgentAction -ComputerName <target> -Action UseToken "j2l3k4hl23h4kj2h34jk23h4lk23"
Invoke-CyberarkAgentAction -ComputerName <target> -Action SupportInfo
Invoke-CyberarkAgentAction -ComputerName <target> -Action StopServ
Invoke-CyberarkAgentAction -ComputerName <target> -Action StartServ
Invoke-CyberarkAgentAction -ComputerName <target> -Action StopPasServ
Invoke-CyberarkAgentAction -ComputerName <target> -Action StartPasServ
Invoke-CyberarkAgentAction -ComputerName <target> -Action LoadFilter
Invoke-CyberarkAgentAction -ComputerName <target> -Action UnloadFilter
#>
Function Invoke-CyberarkAgentAction {
[CmdletBinding()]
Param (
[String][Parameter(Mandatory=$true)][String]$ComputerName,
[String]
[ValidateSet('SuspendPolicies','ResumePolicies','RequestPolicies','UseToken','SupportInfo','StopServ','StartServ','StopPasServ','StartPasAgent')]$Action = 'ResumePolicies',
[String]$Token,
[String]$Path,
[Switch]$InProc
)
Begin {
$vf_agent = "C:\Program Files\CyberArk\Endpoint Privilege Manager\Agent\vf_agent.exe"
$CurrentUser = "$env:username"
$Destination = "C:\Users\$CurrentUser\Downloads\"
}
Process {
Switch ($Action) {
"UseToken" {
If (!$Token) {
$Token = Read-Host -Prompt "Token"
}
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -UseToken $Token" -Wait
}
"SuspendPolicies" {
If ($Token) {
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -SuspendPolicies $Token" -Wait
} Else {
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -SuspendPolicies" -Wait
}
}
"ResumePolicies" {
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -ResumePolicies" -Wait
}
"RequestPolicies" {
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -RequestPolicies" -Wait
}
"SupportInfo" {
$cmd = """$vf_agent"" -SupportInfo"
If ($Path) { $cmd += " ""$Path""" }
If ($InProc) { $cmd += " -inproc" }
Invoke-Process -ComputerName $ComputerName -Command $cmd -Wait
Get-ChildItem "\\$ComputerName\c$\Users\$CurrentUser\AppData\Local\Temp" -filter '????.??.??.??.*.zip' | ForEach-Object {Copy-Item -Path $_.FullName -Destination "$Destination\CyberArk.$ComputerName.$($_.BaseName,$_.Extension)"}
}
'StopServ' {
Write-Host -ForegroundColor Yellow "Warning: Ensure you have first issued a '-UseToken' command."
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -StopServ" -Wait
}
'StartServ' {
Get-Service -Name vf_agent -ComputerName $ComputerName | Start-Service -PassThru
}
'StopPasServ' {
Write-Host -ForegroundColor Yellow "Warning: Ensure you have first issued a '-UseToken' command."
Invoke-Process -ComputerName $ComputerName -Command """$vf_agent"" -StopPasServ" -Wait
}
'StartPasServ' {
Get-Service -Name pasagent -ComputerName $ComputerName | Start-Service -PassThru
}
'LoadFilter' {
Invoke-Process -ComputerName $ComputerName -Command "fltmc.exe load vfdrv" -Wait
}
'UnloadFilter' {
Invoke-Process -ComputerName $ComputerName -Command "fltmc.exe unload vfdrv" -Wait
}
}
}
}
Function Invoke-Process {
[CmdletBinding(DefaultParameterSetName="none")]
Param (
[Parameter(Mandatory=$True)][String]$ComputerName,
[Parameter(Mandatory=$True)][String]$Command,
[Parameter(ParameterSetName='Wait')][Switch]$Wait,
[Parameter(ParameterSetName='PassThru')][Switch]$PassThru
)
Process {
If ((Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName -ErrorAction SilentlyContinue) -as [Bool]) {
$proc = Invoke-WmiMethod -ComputerName $ComputerName -Class Win32_Process -Name Create -ArgumentList "$command"
Switch ($PsCmdlet.ParameterSetName) {
"Wait" {
While (Get-WmiObject -Class Win32_Process -ComputerName $ComputerName -Filter "ProcessId='$($proc.ProcessId)'") {
Start-Sleep -Seconds 1
}
}
"PassThru" {
$proc
}
}
} Else {
Throw "Could connect to $ComputerName"
}
}
}
Export-ModuleMember -Function Invoke-CyberarkAgentAction
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!

