<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Information Sharing: Script to execute vf_agent.exe commands as an Admin remotely within PowerShell in Endpoint Privilege Manager (EPM) Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/endpoint-privilege-manager-epm/information-sharing-script-to-execute-vf-agent-exe-commands-as/m-p/1356944#M3441</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jun 2019 08:12:04 GMT</pubDate>
    <dc:creator>CyberArkAlumni</dc:creator>
    <dc:date>2019-06-26T08:12:04Z</dc:date>
    <item>
      <title>Information Sharing: Script to execute vf_agent.exe commands as an Admin remotely within PowerShell</title>
      <link>https://live.paloaltonetworks.com/t5/endpoint-privilege-manager-epm/information-sharing-script-to-execute-vf-agent-exe-commands-as/m-p/1356943#M3440</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can see all the options with: Get-Help Invoke-CyberarkAgentAction&lt;/P&gt;&lt;P&gt;&amp;nbsp;To execute this- open PowerShell as an Administrator...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**Pre-Req: You need admin access to spawn processes on the local machine**&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Enter-PSSession -ComputerName (ComputerName)&lt;/LI&gt;&lt;LI&gt;Exit-PSSession&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Import the script into PS using import-module command:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Import-Module (EPMSCRIPT.psm1)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;3) Execute "Set-ExecutionPolicy bypass" (if you have not already)&lt;/P&gt;&lt;P&gt;&amp;nbsp;4) Execute the action.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;For example:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;invoke-CyberarkAgentAction -Action SupportInfo -ComputerName EPMMachine123&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This executes the -SupportInfo command then sends the zip file to the download folder on your admin PC:&lt;/P&gt;&lt;P&gt;&amp;nbsp;C:\Users\MyAdminUserID\Downloads\&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;CyberArk.USER12345.2019.06.25.05.22.36 .zip&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Notes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Enjoy!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-TT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;CODE&gt;&amp;lt;#
Wrapper for CyberArk agent commands, designed to run on remote endpoints using WMI
&amp;nbsp;
TODO:
* Test piping
* Passing multiple targets
* Test all parameters
&amp;nbsp;
https://cyberarkdocu.azurewebsites.net/Product-Doc/OnlineHelp/EPM/Latest/en/Content/EPM_PET/Agent%20Commands.htm?Highlight=vf_agent
&amp;nbsp;
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action SuspendPolicies -Token "j2l3k4hl23h4kj2h34jk23h4lk23"
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action SuspendPolicies
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action ResumePolicies
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action RequestPolicies
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action UseToken "j2l3k4hl23h4kj2h34jk23h4lk23"
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action SupportInfo
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action StopServ
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action StartServ
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action StopPasServ
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action StartPasServ
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action LoadFilter
Invoke-CyberarkAgentAction -ComputerName &amp;lt;target&amp;gt; -Action UnloadFilter
&amp;nbsp;
#&amp;gt;
&amp;nbsp;
&amp;nbsp;
Function Invoke-CyberarkAgentAction {
   [CmdletBinding()]
   Param (
      [String][Parameter(Mandatory=$true)][String]$ComputerName,
&amp;nbsp;
      [String]
      [ValidateSet('SuspendPolicies','ResumePolicies','RequestPolicies','UseToken','SupportInfo','StopServ','StartServ','StopPasServ','StartPasAgent')]$Action = 'ResumePolicies',
&amp;nbsp;
      [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\"
   }
&amp;nbsp;
   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)"}
&amp;nbsp;
   
          
             }
         '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
         }
      }
    }
   
}
&amp;nbsp;
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
   )
&amp;nbsp;
   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" {
&amp;nbsp;
               While (Get-WmiObject -Class Win32_Process -ComputerName $ComputerName -Filter "ProcessId='$($proc.ProcessId)'") {
                  Start-Sleep -Seconds 1
               }
            }
            "PassThru" {
               $proc
            }
         }
      } Else {
         Throw "Could connect to $ComputerName"
      }
   }
&amp;nbsp;
   
}
&amp;nbsp;
Export-ModuleMember -Function Invoke-CyberarkAgentAction&lt;/CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 02:16:13 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/endpoint-privilege-manager-epm/information-sharing-script-to-execute-vf-agent-exe-commands-as/m-p/1356943#M3440</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2019-06-26T02:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Information Sharing: Script to execute vf_agent.exe commands as an Admin remotely within PowerShell</title>
      <link>https://live.paloaltonetworks.com/t5/endpoint-privilege-manager-epm/information-sharing-script-to-execute-vf-agent-exe-commands-as/m-p/1356944#M3441</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 08:12:04 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/endpoint-privilege-manager-epm/information-sharing-script-to-execute-vf-agent-exe-commands-as/m-p/1356944#M3441</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2019-06-26T08:12:04Z</dc:date>
    </item>
  </channel>
</rss>

