question

penny1mx avatar image
0 Votes"
penny1mx asked LimitlessTechnology-2700 answered

Problems with gpo & ps1 ...

I have an issue with a PowerShell script with GPO, my script:

Get-AppxPackage -AllUsers | where-object {$.name –notlike “windowscalculator”} | Remove-AppxPackage
Get-appxprovisionedpackage –online | where-object {$
.packagename –notlike “windowscalculator”} | Remove-AppxProvisionedPackage -online

The idea is to delete all the applications provided by Microsoft in Windows 10.

I try to put it as a startup script, in the end, and don't work.

Do you have any idea why ???

windows-server-powershellwindows-group-policy
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

soysoliscarlos avatar image
0 Votes"
soysoliscarlos answered penny1mx commented

Hi @penny1mx a

Thank you for asking this question on the Microsoft Q&A Platform.


Try the recommendations of this post

Sometimes you would need to automate an uninstall of an application through Group Policies (GPO). This can be done by running a PowerShell script. Firstly create a PowerShell script as below:

 $appplication = Get-WmiObject -Class Win32_Product | Where-Object
 {$_.Name -match "My Application Name"}
 $application.Uninstall()

Save the file and create a new GPO and set the script to load by setting up the Computer Configuration/ Policies/ Windows Settings/ Scripts/ Startup.


Hope this helps,
Carlos Solís Salazar


Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
NOTE: To answer you as quickly as possible, please mention me in your reply.









· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks so much, Carlos,

I try, and the same results don't run the PS1.

I don't know why !!!

0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered

Add a Start-Transcript command to your .ps1. It will create a log of everything the script does.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

If the commands don't generate any output at all, you may need to add -verbose to the commands to get additional info.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

penny1mx avatar image
0 Votes"
penny1mx answered MotoX80 commented

Hi !!!

I put it Start-Transcript when I run manually to create the log file, but when I run by the policy do anything !!!

I'm really frustrating the PS1 doesn't run !!!

Thanks so much ...

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Unfortunately, we can't see what is on your screen, so we don't know what you have configured.

http://woshub.com/running-powershell-startup-scripts-using-gpo

Do you see the .ps1 file on the PC? Does the Start-Transcript cmdlet point to an existing folder? What is the Powershell execution policy on the machine? Is that set to allow execution?

Check the Powershell log in Applications and Services Logs\Microsoft\Microsoft-Windows-PowerShell/Operational

Did you run gpresult to verify that the policy is applied to this particular machine?

0 Votes 0 ·

Thanks, Moto !!!

Finally, I see the error:

Get-AppxPackage : Access is denied

Do you have any idea why run that PS1 over a normal user whit admin rights ???

Thanks so much !!!

0 Votes 0 ·

While the user might be a member of the Administrators group, the Powershell process is not running elevated, so it's really doesn't have admin rights. The internet has some suggestions.

https://www.bing.com/search?q=windows+run+logon+script+elevated

Another option would be to run a scheduled task as the system account along with "run with highest privileges". You should only have to run it one time.

I want to warn you though, I have a test VM that I play with, and I tried to remove all AppxPackages and some of them just would not go away. Seems to be a Windows "feature".

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello

Thank you for your question and reaching out. I can understand you are having issues related to related start-up script to remove app.

Please try to put pause or Sleep before starting the script as running PowerShell script can be slow compared to .bat script and it requires to be in User-context mode after user profile is loaded.

Please also put logging of errors to review any potential syntax or other errors



--If the reply is helpful, please Upvote and Accept as answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.