locked
Stopping process on a remote computer RRS feed

  • Question

  • Hello

    I'm trying to stop the outlook process on a remote computer (Stop-Process -Name Outlook).

    I have tried creating a remote session and running the script in a scriptblock, but all that happens is it stops my local outlook process.

    I have tried Invoke-Command after getting the process name  (Get-Process -Name Outlook | Stop-Process Outlook).

    But nothing is working.

    Once I get this completed, it will simply be a matter of finding and copying the .pst, .ost files to the server (for archive backups).  But I need to shut down outlook gracefully first (if it's running).

    $Computer = "anx-6m" #Will be replaced with Get-ADComputer
    $ProcessActive = Get-Process outlook* -ComputerName $Computer -ErrorAction SilentlyContinue
    
    if($ProcessActive -eq $null)
    {
     Write-Host "Not Active"
    }
    else
    {
     Write-host "Active" + "," + "Shutting down...."
     Invoke-command -Computername $Computer {Stop-process $ProcessActive}
    }
    

    In the above script, as I mentioned, I also tried creating a remote session and running the command there, but did not work.

    Any suggestions would be appreciated.

    Thank you

    Terry

    Thursday, August 1, 2019 5:02 PM

All replies

  • "Process" is per user. YUO have to access the specific users process. The default is your local session and all other sessions if you ae an admin.

    Just tell the user to run "Stop-Process Outlook" at a prompt and the users process will be the one stopped.

    You cannot remote into another users session.  It I snot possible with PowerShell.  YOu can use TS management to attach to a users RDS session and kill a process.


    \_(ツ)_/

    Thursday, August 1, 2019 5:06 PM
  • Hello,

    Have you tried this:

    $s = New-PSSession -ComputerName Server02 -Credential Domain01\User01

    Invoke-Command -Session $s -ScriptBlock {Get-Process -Name Outlook |kill}

    Dont forget to run the following command on the remote computer:

    Enable-PSRemoting -Force -SkipNetworkProfileCheck



    Thursday, August 1, 2019 5:17 PM
  • Hello,

    Have you tried this:

    $s = New-PSSession -ComputerName Server02 -Credential Domain01\User01

    Invoke-Command -Session $s -ScriptBlock {Get-Process -Name Outlook |kill}

    Dont forget to

    Enable-PSRemoting -Force -SkipNetworkProfileCheck

    This will only work with admin accounts.  Users are not normally admins.  The code will also not kill outlook in the users session.  You cannot remote into an existing interactive session with any tool.


    \_(ツ)_/

    Thursday, August 1, 2019 5:21 PM
  • invoke-command -computername "anx-6m" -ScriptBlock {get-process *outlook* | kill}

    this works for me from my admin account to a regular user.

    We also have a gpo that enables PSremoting like jrv says


    Justin

    Thursday, August 1, 2019 7:27 PM
  • invoke-command -computername "anx-6m" -ScriptBlock {get-process *outlook* | kill}

    this works for me from my admin account to a regular user.

    We also have a gpo that enables PSremoting like jrv says


    Justin

    Yes because, as an admin, you will kill all copies of outlook for all users which may not be what you want.   If you are targeting a user on an RDS server then all users Outlook apps will be killed.


    \_(ツ)_/

    Thursday, August 1, 2019 7:34 PM
  • get-process outlook -IncludeUserName  |
         Where{ $_.UserName -eq 'alpha\jamith'} |
         Stop-Process


    \_(ツ)_/


    Thursday, August 1, 2019 7:38 PM
  • Without remoting we can use WMI:

    Get-WmiObject Win32_Process -Filter "Name='Outlook.exe'"  -Computer MyRemotePC | 
        Where-Object{$_.GetOwner().User -eq 'jsmith' } |
        ForEach-Object{$_.Terminate()}
    


    \_(ツ)_/

    Thursday, August 1, 2019 7:43 PM
  • I created some time ago a script that kills processes on remote computers (inside the same domain)

    https://gallery.technet.microsoft.com/scriptcenter/Process-Killer-for-local-836f5b46

    Probably that would help you.

    Friday, August 2, 2019 8:49 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, September 6, 2019 12:57 PM