Page 1 of 1

Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 6:21 am
by ITEngineer
Hi,

Is there any way to run the below script with some additional checking to skip the uninstallation when the AppX is not even listed?

Note: the script is also modified (but failed) to not show anything on the user screen.

Code: Select all

$t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
add-type -name win -member $t -namespace native
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)

Get-AppxProvisionedPackage -AllUsers "2414FC7A.Viber" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "41038Axilesoft.ACGMediaPlayer" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "46928bounde.EclipseManager" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "4DF9E0F8.Netflix" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "64885BlueEdge.OneCalendar" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "7EE7776C.LinkedInforWindows" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "828B5831.HiddenCityMysteryofShadows" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "89006A2E.AutodeskSketchBook" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "9E2F88E3.Twitter" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "A278AB0D.DisneyMagicKingdoms" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "A278AB0D.DragonManiaLegends" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "A278AB0D.MarchofEmpires" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "ActiproSoftwareLLC.562882FEEB491" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "AdobeSystemsIncorporated.AdobePhotoshopExpress" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "CAF9E577.Plex" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "D52A8D61.FarmVille2CountryEscape" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "D5EA27B7.Duolingo-LearnLanguagesforFree" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "DB6EA5DB.CyberLinkMediaSuiteEssentials" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "DolbyLaboratories.DolbyAccess" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "Drawboard.DrawboardPDF" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "E046963F.LenovoCompanion" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "Facebook.Facebook" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "Fitbit.FitbitCoach" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "GAMELOFTSA.Asphalt8Airborne" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "KeeperSecurityInc.Keeper" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "LenovoCorporation.LenovoID" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "LenovoCorporation.LenovoSettings" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "Microsoft.MicrosoftSolitaireCollection" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "Microsoft.MinecraftUWP" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "Nordcurrent.CookingFever" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "PandoraMediaInc.29680B314EFC2" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "SpotifyAB.SpotifyMusic" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "WinZipComputing.WinZipUniversal" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "XINGAG.XING" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "flaregamesGmbH.RoyalRevolt2" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "king.com.BubbleWitch3Saga" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "king.com.CandyCrushSaga" | Remove-AppxProvisionedPackage
Get-AppxProvisionedPackage -AllUsers "king.com.CandyCrushSodaSaga" | Remove-AppxProvisionedPackage

exit
The script above will be executed for thousands of my users worldwide daily when they logon, so how to make sure it is not displaying command prompt window?

Any help would be greatly appreciated.

Re: Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 6:39 am
by jvierra
A user cannot remove a package. This can only be done by an administrator.

I think you really want to use "Get-AppxPackage".

Read the help for both and decide which thing you are trying to do.

Re: Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 6:51 pm
by ITEngineer
jvierra wrote:
Thu Dec 06, 2018 6:39 am
A user cannot remove a package. This can only be done by an administrator.

I think you really want to use "Get-AppxPackage".

Read the help for both and decide which thing you are trying to do.
OK, here's the updated script.

Code: Select all

$t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
add-type -name win -member $t -namespace native
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)

Get-AppxPackage -AllUsers "2414FC7A.Viber" | Remove-AppxPackage
Get-AppxPackage -AllUsers "41038Axilesoft.ACGMediaPlayer" | Remove-AppxPackage
Get-AppxPackage -AllUsers "46928bounde.EclipseManager" | Remove-AppxPackage
Get-AppxPackage -AllUsers "4DF9E0F8.Netflix" | Remove-AppxPackage
Get-AppxPackage -AllUsers "64885BlueEdge.OneCalendar" | Remove-AppxPackage
Get-AppxPackage -AllUsers "7EE7776C.LinkedInforWindows" | Remove-AppxPackage
Get-AppxPackage -AllUsers "828B5831.HiddenCityMysteryofShadows" | Remove-AppxPackage
Get-AppxPackage -AllUsers "89006A2E.AutodeskSketchBook" | Remove-AppxPackage
Get-AppxPackage -AllUsers "9E2F88E3.Twitter" | Remove-AppxPackage
Get-AppxPackage -AllUsers "A278AB0D.DisneyMagicKingdoms" | Remove-AppxPackage
Get-AppxPackage -AllUsers "A278AB0D.DragonManiaLegends" | Remove-AppxPackage
Get-AppxPackage -AllUsers "A278AB0D.MarchofEmpires" | Remove-AppxPackage
Get-AppxPackage -AllUsers "ActiproSoftwareLLC.562882FEEB491" | Remove-AppxPackage
Get-AppxPackage -AllUsers "AdobeSystemsIncorporated.AdobePhotoshopExpress" | Remove-AppxPackage
Get-AppxPackage -AllUsers "CAF9E577.Plex" | Remove-AppxPackage
Get-AppxPackage -AllUsers "D52A8D61.FarmVille2CountryEscape" | Remove-AppxPackage
Get-AppxPackage -AllUsers "D5EA27B7.Duolingo-LearnLanguagesforFree" | Remove-AppxPackage
Get-AppxPackage -AllUsers "DB6EA5DB.CyberLinkMediaSuiteEssentials" | Remove-AppxPackage
Get-AppxPackage -AllUsers "DolbyLaboratories.DolbyAccess" | Remove-AppxPackage
Get-AppxPackage -AllUsers "Drawboard.DrawboardPDF" | Remove-AppxPackage
Get-AppxPackage -AllUsers "E046963F.LenovoCompanion" | Remove-AppxPackage
Get-AppxPackage -AllUsers "Facebook.Facebook" | Remove-AppxPackage
Get-AppxPackage -AllUsers "Fitbit.FitbitCoach" | Remove-AppxPackage
Get-AppxPackage -AllUsers "GAMELOFTSA.Asphalt8Airborne" | Remove-AppxPackage
Get-AppxPackage -AllUsers "KeeperSecurityInc.Keeper" | Remove-AppxPackage
Get-AppxPackage -AllUsers "LenovoCorporation.LenovoID" | Remove-AppxPackage
Get-AppxPackage -AllUsers "LenovoCorporation.LenovoSettings" | Remove-AppxPackage
Get-AppxPackage -AllUsers "Microsoft.MicrosoftSolitaireCollection" | Remove-AppxPackage
Get-AppxPackage -AllUsers "Microsoft.MinecraftUWP" | Remove-AppxPackage
Get-AppxPackage -AllUsers "Nordcurrent.CookingFever" | Remove-AppxPackage
Get-AppxPackage -AllUsers "PandoraMediaInc.29680B314EFC2" | Remove-AppxPackage
Get-AppxPackage -AllUsers "SpotifyAB.SpotifyMusic" | Remove-AppxPackage
Get-AppxPackage -AllUsers "WinZipComputing.WinZipUniversal" | Remove-AppxPackage
Get-AppxPackage -AllUsers "XINGAG.XING" | Remove-AppxPackage
Get-AppxPackage -AllUsers "flaregamesGmbH.RoyalRevolt2" | Remove-AppxPackage
Get-AppxPackage -AllUsers "king.com.BubbleWitch3Saga" | Remove-AppxPackage
Get-AppxPackage -AllUsers "king.com.CandyCrushSaga" | Remove-AppxPackage
Get-AppxPackage -AllUsers "king.com.CandyCrushSodaSaga" | Remove-AppxPackage

exit
My goal here is to be able to remove all AppX for the users as part of the Logon script, but do not display the command prompt window.

So enforce only the below Appx:
Microsoft.MicrosoftStickyNotes
Microsoft.StorePurchaseApp
Microsoft.WindowsCalculator
Microsoft.WindowsStore

Re: Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 7:01 pm
by jvierra
Won't work. Users cannot remove packages for other users.

Re: Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 7:04 pm
by ITEngineer
jvierra wrote:
Thu Dec 06, 2018 7:01 pm
Won't work. Users cannot remove packages for other users.
Hi Mr. Vierra,

Yes, I have already think about that.

I have already created the Group Policy steps to implement
Computer Configuration\Administrative Templates\Windows Components\Cloud Content
However, This setting only applies to Enterprise and Education SKUs

So I I assume by removing the -AllUser parameter it will work fine as logon script?

but the problem is how to hide the Command Prompt window?

Re: Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 7:32 pm
by jvierra
This does not need to be done on every logon.

Use you admin account to remove the provisioning package once then remove all users deployment and the problem should be gone.

Re: Running Powershell with no Command Prompt display as logon script?

Posted: Thu Dec 06, 2018 9:23 pm
by ITEngineer
jvierra wrote:
Thu Dec 06, 2018 7:32 pm
This does not need to be done on every logon.

Use you admin account to remove the provisioning package once then remove all users deployment and the problem should be gone.
Yes, but that's already too late since the computer has been deployed companywide.

Anyway, is there anyu trick or steps to make sure the PowerShell command prompt is stayed hidden when executed?