尝试通过脚本卸载Carbon Black Bit9。有没有更好的方法来运行psession?

时间:2019-05-03 13:57:16

标签: powershell

我正在尝试在没有PSEXEC的远程代理上卸载炭黑保护。我得知Pssession可以替代它。该程序所要做的只是将卸载实用程序推送到包装盒中。禁用炭黑的篡改保护,并运行该实用程序。

当我运行代码时,它似乎运行良好,但是我注意到,一旦执行了pssession部分,命令就会在我的本地计算机(而不是目标远程PC)上运行。我的目标是单击一个按钮,输入PC名称,并将其全部自动化。

在Powershell ISE中是否有更好的方法来运行它?

当我逐行运行代码时,它可以正确执行。

        $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" 
    & '.\AgentUninstallUtility.exe'+  -password $cliPassword

    Exit-PSSession

pssession下的远程PC应该删除了代理程序/文件。

0 个答案:

没有答案