title: Attempting to uninstall Carbon Black Bit9 Via a script. Is there a better way to run psession?
body: <p>I am trying to uninstall carbon black protection on a remote agent without PSEXEC. I was informed Pssession is a great replacement for that. All this program does is it pushes an uninstall utility to the box. Disables tamper protection of carbon black, and runs the utility.  </p>
  
  <p>When I run the code it appears to be running fine however I noticed once it his the pssession portion the commands are running against my local machine, not the target remote PC.   I am aiming to click a button, enter a PC name and have it all automated. </p>
  
  <p>Is there a better way to run this in Powershell ISE?</p>
  
  <p>When I run the code line by line it executes correctly. </p>
  
  <pre><code>        $Computer = "pcname1"
  
      Enter-PSSession $Computer
  
  
      #Copy uninstall Agent to PC Write-Host "Copying uninstall agent to $Computer"
  
      New-PSDrive -Name UserUNC -PSProvider FileSystem -Root "\\$Computer\c$\" | out-null 
      Copy-Item -Path  "\\Source\AgentUninstallUtility.exe" -Destination "UserUNC:\Temp"
      Remove-PSDrive UserUNC 
      Write-Host "Item copied to temp"
  
  
  
  
      Write-Host "Pssesion entered"
  
      #obtain CLI passwordfrom CB console
  
      Write-Host "Finding CLI Password"
      $resource = "SOMEWSERVER/omputer?q=name:*" + $env:computername
      $url = "SOMExml"
      $configlist = "C:\Temp\configlistwithdeleteditems.xml"
  
      [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  
      $wc = New-Object System.Net.WebClient
      $wc.DownloadFile($url, $configlist)
  
      $webResponsey = [System.Net.WebRequest]::Create($resource)
      $webResponsey.Method = "GET"
      $webResponsey.ContentType='application/json; charset=utf-8'
      $webResponsey.Headers.Add("X-Auth-Token", "soemtoken")
  
      $Response= $webResponsey.GetResponse()
      $ResponseStream = $Response.GetResponseStream()
      $ReadStream = New-Object System.IO.StreamReader $ResponseStream
      $jsonresult = $ReadStream.ReadToEnd()
  
      $saveme = $jsonresult | Out-String
      $cliPassword = $saveme -replace '(?s).*CLIPassword":"([^"]*)".*', '$1'
  
      Write-Host "CLI password is " $cliPassword
  
  
  
      Write-Host "Changing directory to Parity Agent"
      cd 'C:\Program Files (x86)\Bit9\Parity Agent'
  
  
      .\DasCLI.exe password $cliPassword
  
      Write-Host "Disabling Tamper protect"
      .\DasCLI.exe tamperprotect 0
  
      Write-Host "Changing Directory to Temp"
      cd 'C:\Temp\'
  
      Write-Host "Running Agent Uninstall Utility" 
      &amp; '.\AgentUninstallUtility.exe'+  -password $cliPassword
  
      Exit-PSSession
  </code></pre>
  
  <p>The remote PC under the pssession should have the agent / files removed.</p>