I have a PowerShell script to uninstall the two problem KB's MS has released, we are pushing it through with our RMM as run PowerShell as admin, but if the user is currently logged in that does not have admin priv. the script errors out with the requested operation requires elevation. Here is the command being run:
Get-WindowsPackage -Online | ?{$_.ReleaseType -like "*Update*"} |
%{Get-WindowsPackage -Online -PackageName $_.PackageName} |
?{$_.Description -like "*KB5000802*"} | Remove-WindowsPackage -Online -Restart /quiet
Is there some way to get around the elevated privilege's issue?
Related
Problem -
Unable to uninstall dell optimizer service
Long version -
i am looking to write what should be a very basic script for removing dell optimizer. when its fully installed and i run get-package I get the following.
When this is uninstalled by piping into uninstall-package. we are still left with dell optimizer service.
this is after stopping the services as well.
PS C:\WINDOWS\system32> Get-Package -Name *optimizer*
Name Version Source ProviderName
---- ------- ------ ------------
Dell Optimizer 2.0.651.0 C:\Program Files\Dell\DellOpt... msi
DellOptimizerUI 2.0.651.0 C:\Program Files (x86)\Dell\D... msi
Dell Optimizer Service 2.0.651.0 Programs
dell optimizer service in programs and features
the uninstall string as below when run does not accept -remove or -runfromtemp HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
"C:\Program Files (x86)\InstallShield Installation Information{286A9ADE-A581-43E8-AA85-6F5D58C7DC88}\DellOptimizer.exe" -remove -runfromtemp
+ ... A9ADE-A581-43E8-AA85-6F5D58C7DC88}\DellOptimizer.exe" -remove -runfro ...
+ ~~~~~~~
Unexpected token '-remove' in expression or statement.
At line:1 char:199
+ ... -A581-43E8-AA85-6F5D58C7DC88}\DellOptimizer.exe" -remove -runfromtemp
+ ~~~~~~~~~~~~
Unexpected token '-runfromtemp' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
the exe is located at
C:\Program Files (x86)\InstallShield Installation Information{286A9ADE-A581-43E8-AA85-6F5D58C7DC88}\DellOptimizer.exe
I have used 7zip to unpackage the .exe to see if there was an uninstall file but to no avail.
I believe it has something to do with its providername being program and also the dell optimizer service does not appear when you search for the below in ciminstance.
Im unsure how to find which CIMclass it would fall into as it could be a step in the right direction
PS C:\WINDOWS\system32> Get-CimInstance -ClassName Win32_Product | Sort-Object
Has anyone done something like this before? or anything i could try?
i worked it out. it was a silly mistake and needed to run the uninstall string in command prompt
#stop dell optimizer services
Get-Service -Name "DellOptimizer" | Stop-Service
#Get Dell Optimizer from registry
$uninstallstring = get-itemproperty 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object { $_.DisplayName -match "optimizer service"}
#get the uninstall string for dell optimizer
$uninstallstring = $removeapp.UninstallString
#add the silent parameter and run throguh cmd to uninstall
cmd /c $uninstallstring -silent
fix for your script
#stop dell optimizer services
Get-Service -Name "DellOptimizer" | Stop-Service
#Get Dell Optimizer from registry
$uninstallstring = get-itemproperty 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object { $_.DisplayName -match "optimizer service"}
#get the uninstall string for dell optimizer
$uninstallstring = $uninstallstring.UninstallString
#add the silent parameter and run throguh cmd to uninstall
cmd /c $uninstallstring -silent
why not just follow their documentation and download the exe. extract it to get the DellOptimizer.exe package it up with a simple powershell script that run DellOptimizer.exe /remove /silent
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
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.
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
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
I am trying to uninstall the older version of the software and install the latest version. I have an uninstall script and an install script that does this. When I run the script as Powershell as Admin, the script executes successfully, but in non Admin mode, it prompts for a popup asking for confirmation,
Since I am trying to automate via pipeline I need to skip or suppress this popup,
msiexec.exe /i "installer.msi" /q
$app = Get-WmiObject -Class Win32_Product -Filter "Name = 'installer'" | Remove-WmiObject
I have tried using /q, /quiet that did not help
Is there any way to suppress such prompt so that it can continue silently?
The module appears to be installed, but cannot find or use commands. Get-Command returns nothing.
Have you experienced this? What is the cause of this situation?
PS C:\> Find-Module -Name GetStuff | Install-Module -Scope CurrentUser
PS C:\> Get-Command -Module GetStuff
User running PowerShell 5.1.17134.858 fails
User running PowerShell 5.1.17763.1490 succeeds
Case closed until user tests newer version.
I write this command for powershell. I want to stop the running process of taskmgr from PowerShell.
Get-Service | Where-Object {$_.Status -eq "Running"}
And how to stop process those running processes?
Task Manager is a process, not a service.
So, in order to stop it from PowerShell you need to run:
Stop-Process -Name Taskmgr -Force
PS: You will need to run the powershell as administrator in order to stop the process.
Best regards,