0

I want to run this powershell script with admin privileges so it won't give me the error:

Script Output with error

Here is the script:

$processes = "PDStyleAgent", "AdobeIPCBroker", "CCXProcess", "RichVideo64", "CCLibrary", "AdobeNotificationClient", "AdobeUpdateService", "PDHanumanSvr", "PDR"

Foreach ($process in $processes){
    try {
    $f = Get-Process $process -ErrorAction Stop
    $f | kill
    Write-Output "$process killed."
        } 
    catch [Microsoft.PowerShell.Commands.ProcessCommandException]{
    Write-Output "No instances of $process running."
        }   
}

Start-Sleep -Seconds 3

I want to run this script so it kill the processes that are giving errors

3 Answers3

1

Some way to run PowerShell with admin privileges:

  1. Search Powershell from the Windows search icon OR click the Windows button from the keyboard --> write Powershell --> You will see the Windows PowerShell --> Right-click on Powershell then click Run as administrator.
  2. Run this command of a PowerShell console: Start-Process powershell -Verb runAs
  3. Run your script from PowerShell like this: PowerShell -f C:\ScriptPath

For more details, you can check this StackOverflow question and answer.

1

I'm not sure what exactly you are asking about. If you want to start a script as administrator, you need to open PowerShell window "As administrator".

BTW, the script itself can be simplified without losing functionality:

$processes = "PDStyleAgent", "AdobeIPCBroker", "CCXProcess", "RichVideo64", "CCLibrary", "AdobeNotificationClient", "AdobeUpdateService", "PDHanumanSvr", "PDR"

Get-Process -Name $processes -ErrorAction SilentlyContinue | Stop-Process -Verbose
MikeSh
  • 352
  • 1
  • 5
0

1.Create a shortcut to your Powershell script on your desktop

2.Right-click the shortcut and click Properties

3.Click the Shortcut tab

4.Click Advanced

5.Select Run as Administrator

NOTE: add powershell -f in front of the script path

AABULUT
  • 50
  • 4