Apr 17, 2016

Windows 10 - Create & Run PowerShell Script

In one of my previous post where I've shown on how to remove/uninstall Windows 10 built-in apps, now it's time to create your own PowerShell script to run all those command automatically.

Imagine you need to do this everytime you performed a new installation, well if 1-2 system then it might be OK with..... how about 10-50 systems ? I surely will want to do this automatically.

Of course firstly you need to create the script first then save it and run it at a later stage.

1. Open --> PowerShell ISE.



2. You will see a new application opened.



3. Create your script in the right pane as shown.


For easy reference, you just need to copy & paste the following cmdlet into the pane. You may remove any cmdlet as you deem fits your requirements.


Get-AppxPackage -AllUsers *3dbuilder* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowsalarms* | Remove-AppxPackage
Get-AppxPackage -AllUsers *zunevideo* | Remove-AppxPackage
Get-AppxPackage -AllUsers *officehub* | Remove-AppxPackage
Get-AppxPackage -AllUsers *skypeapp* | Remove-AppxPackage
Get-AppxPackage -AllUsers *getstarted* | Remove-AppxPackage
Get-AppxPackage -AllUsers *zunemusic* | Remove-AppxPackage
Get-AppxPackage -AllUsers *solitairecollection* | Remove-AppxPackage
Get-AppxPackage -AllUsers *bingfinance* | Remove-AppxPackage
Get-AppxPackage -allusers *bingnews* | Remove-AppxPackage
Get-AppxPackage -AllUsers *people* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowsphone* | Remove-AppxPackage
Get-AppxPackage -AllUsers *commsphone* | Remove-AppxPackage
Get-AppxPackage -AllUsers *photos* | Remove-AppxPackage
Get-AppxPackage -AllUsers *bingsports* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowsstore* | Remove-AppxPackage
Get-AppxPackage -AllUsers *bingweather* | Remove-AppxPackage
Get-AppxPackage -AllUsers *xboxapp* | Remove-AppxPackage
Get-AppxPackage -AllUsers *twitter* | Remove-AppxPackage
Get-AppxPackage -AllUsers *office.sway* | Remove-AppxPackage
Get-AppxPackage -AllUsers *xboxonesmartglass* | Remove-AppxPackage
Get-AppxPackage -AllUsers *messaging* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowscommunicationsapps* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowscamera* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowsmaps* | Remove-AppxPackage
Get-AppxPackage -AllUsers *soundrecorder* | Remove-AppxPackage
Get-AppxPackage -AllUsers *onenote* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowsscan* | Remove-AppxPackage
Get-AppxPackage -AllUsers *windowscalculator* | Remove-AppxPackage


4. Now save the newly created script to your preferred location, also you need to ensure the file extension is ".ps1" before saving it.



5. Now you must run --> PowerShell with "administrator" rights by right-click --> Run as administrator option as shown below.



6. Note the "Administrator" level is shown on the top left corner of the windows.



7. As my script file was save in [D:] folder, so must first change the working directory first, your folder maybe different from mine. Proper path is required.



8. Now type the script's filename as shown below and press --> [ENTER] key.



9. You will definitely encounter this error, don't worry as this is normal. This is because the "PowerShell Execution Policy" prevents any unauthorised scripts from running as security measures, which I very much like this idea (even though some find it troublesome).



10. Now type this cmdlet --> Get-ExecutionPolicy --> [ENTER]. It will display the current status of the policy, note the "Restricted" level as shown below screen.



11. Now to change it type the following cmdlet --> Set-ExecutionPolicy Unrestricted --> [ENTER], this will change the level to "Unrestricted" which will allows you to run the script. When prompted just type --> "A" key --> [ENTER] to continue.



12. Type the script filename again and this time you should be able to run it without any error message, if successful you should be able to see the below screen. This will takes some times to complete so be patience.



13. Once completed, you might want to change back the policy back to "Restricted" as security measure, just type --> Set-ExecutionPolicy Restricted --> [ENTER] key.



14. To really do this automatically, you will need to create a batch file to first change the policy level, then run the script and finally change back the policy to default level.

For that will be another posting coming soon.

HAPPY CODING !!!

No comments:

Post a Comment