I want to run this powershell script with admin privileges so it won't give me the 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
CodePudding user response:
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
CodePudding user response:
Some way to run PowerShell with admin privileges:
- 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.
- Run this command of a PowerShell console:
Start-Process powershell -Verb runAs - Run your script from PowerShell like this:
PowerShell -f C:\ScriptPath
For more details, you can check this StackOverflow question and answer.
CodePudding user response:
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
