Link to home
Start Free TrialLog in
Avatar of Debrata 1
Debrata 1

asked on

PowerShell

I am trying to uninstall a software from Computers in the network. The script below works on  my computer but when i create GPO for user log on script it does not work. can anyone help with this ?

Get-wmiobject  win32_product | ?{$_.name -match "Java"} | %{$_.uninstall()}
Avatar of Hello There
Hello There

You cannot put Powershell command into batch file.

The command you provided must be saved into .PS1 file.
@Hello There: Why do you think it is in a batch?
User generated image
You can also run
PowerShell.exe -ExecutionPolicy ByPass -File TheFile.ps1

Open in new window

I only assume... due to lack of info.

Why do you think it is a PS script?
:D
Probably it is but I have to exclude this as well.
Avatar of Debrata 1

ASKER

@Hello it's not a batch it's saved as .ps1
@Shaun
PS.PNG
Thanks. :D

Specify the path to the script... UNC path if the script is stored on shared media.
Thank you

@ Hello I am testing it on my computer first i will put the UNC path in the GPO after the script runs successfully
PS2.PNG
I see that running PS scripts is restricted...
@ Hello that is the point of "PowerShell.exe -ExecutionPolicy ByPass" in the script

@Shaun Vermaak do you have any idea ? I am a new to PowerShell
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6&viewFallbackFrom=powershell-Microsoft.PowerShell.Core
You can not put a software install, uninstall as a user GPO, as the user might not gave requisite rights.

Since you are using powershell, use psexec from sysinternals to script the process.

Or use a computer GPO on shutdown or startup to run your command which will run at system privilege and has requisite rights to install/remove software.

If you use software deployment policy, commonly the package there includes an option that you can revoke and it will be uninstalled.
@arnold
Thanks for the info. I add it to computer startup script GPO and linked it to the OU that has computers But the script still didn't run.
One to address whether the script did not run because it could not, use a bat type wrapper to trigger the power shell run.

Did the GPO refresh before system boot?

CAN YOU CONFIRM THAT RUNNING THE command as you outline in an elevated cmd window does what you expect?
Deploy the PowerShell to computer with GPO file preference
Create the Scheduled task with GPO schedule task preference (using NT Authority\SYSTEM as user)

Both of these actions int here
https://www.experts-exchange.com/articles/31583/Active-Directory-Securely-Set-Local-Account-Passwords.html

In Scheduled task use
Command: PowerShell.exe
Argument: -ExecutionPolicy Bypass -File "PathToYourPowerShell\PowerShellFile.ps1"

Remember the F3 shortcut in preference to access environmental variables
Thank you all,

PowerShell is not working for me so I just used a simple batch and add it to start up GPO.

MsiExec.exe /x {ProductID} /qn
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.