Hello,
I need to run a PowerShell script from a package (to remove unnecessary apps from Windows 10 after an upgrade).
I've found several forum posts about this, but they all handle it differently!
Is there a cleaner solution?
For your information:
- WAPT version installed: 1.3.13
- Server OS: Debian Jessie
- Administration/package creation machine OS: Windows 10
Thank you
[SOLVED] How to run a PowerShell script?
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
-
olaplanche
- Messages: 178
- Registration: January 26, 2017 - 11:11
Last edited by olaplanche on Dec 19, 2018 - 10:12, edited 2 times.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- sfonteneau
- WAPT Expert
- Messages: 2318
- Registered: July 10, 2014 - 11:52 PM
- Contact :
use the run_powershell function
For example :
It's the cleanest
For example :
Code: Select all
run_powershell('Get-AppxPackage -Name Microsoft.Windows.Cortana -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}')-
olaplanche
- Messages: 178
- Registration: January 26, 2017 - 11:11
Hello and thank you for the reply.
I am currently testing with the following package:
Only the middle command seems to work (no issues with a new user account). I can't find anything about the `run_powershell` function; is it possible to get feedback like in the PowerShell console? The Wapt console isn't reporting any errors, yet the apps aren't being removed from the administrator account!
THANKS
I am currently testing with the following package:
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
uninstallkey = []
def install():
run_powershell('Get-AppXPackage -User Administrateur | where-object {$_.name –notlike “*store*”} | Remove-AppxPackage')
run_powershell('Get-appxprovisionedpackage –online | where-object {$_.packagename –notlike “*store*”} | Remove-AppxProvisionedPackage -online')
run_powershell('Get-AppxPackage -AllUsers | where-object {$_.name –notlike “*store*”} | Remove-AppxPackage')THANKS
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
-
olaplanche
- Messages: 178
- Registration: January 26, 2017 - 11:11
Additional information:
I am using the x64 version of powershell and this could be due to limitations of it for the system account.
I am using the x64 version of powershell and this could be due to limitations of it for the system account.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
-
olaplanche
- Messages: 178
- Registration: January 26, 2017 - 11:11
Good morning,
I'm bringing this problem up again, as I still haven't solved it.
Quite a few things have changed in the meantime, namely:
- Installed WAPT version: 1.6.2.7
- Server OS: Debian Stetch
- Operating system of the administration/package creation machine: Windows 10
Next, I use a new script during my MDT deployment; here it is:
I would like to use it in a wapt package, but I don't see how...
Can someone point me in the right direction?
THANKS
I'm bringing this problem up again, as I still haven't solved it.
Quite a few things have changed in the meantime, namely:
- Installed WAPT version: 1.6.2.7
- Server OS: Debian Stetch
- Operating system of the administration/package creation machine: Windows 10
Next, I use a new script during my MDT deployment; here it is:
Code: Select all
# Functions
function Write-LogEntry {
param(
[parameter(Mandatory=$true, HelpMessage="Value added to the RemovedApps.log file.")]
[ValidateNotNullOrEmpty()]
[string]$Value,
[parameter(Mandatory=$false, HelpMessage="Name of the log file that the entry will written to.")]
[ValidateNotNullOrEmpty()]
[string]$FileName = "RemovedApps.log"
)
# Determine log file location
$LogFilePath = Join-Path -Path $env:windir -ChildPath "Temp\$($FileName)"
# Add value to log file
try {
Add-Content -Value $Value -LiteralPath $LogFilePath -ErrorAction Stop
}
catch [System.Exception] {
Write-Warning -Message "Unable to append log entry to RemovedApps.log file"
}
}
# Get a list of all apps
Write-LogEntry -Value "Starting built-in AppxPackage and AppxProvisioningPackage removal process"
$AppArrayList = Get-AppxPackage -PackageTypeFilter Bundle -AllUsers | Select-Object -Property Name, PackageFullName | Sort-Object -Property Name
# White list of appx packages to keep installed
$WhiteListedApps = @(
"Microsoft.DesktopAppInstaller",
"Microsoft.WindowsCalculator",
"Microsoft.WindowsStore"
)
# Loop through the list of appx packages
foreach ($App in $AppArrayList) {
# If application name not in appx package white list, remove AppxPackage and AppxProvisioningPackage
if (($App.Name -in $WhiteListedApps)) {
Write-LogEntry -Value "Skipping excluded application package: $($App.Name)"
}
else {
# Gather package names
$AppPackageFullName = Get-AppxPackage -Name $App.Name | Select-Object -ExpandProperty PackageFullName
$AppProvisioningPackageName = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like $App.Name } | Select-Object -ExpandProperty PackageName
# Attempt to remove AppxPackage
if ($AppPackageFullName -ne $null) {
try {
Write-LogEntry -Value "Removing application package: $($App.Name)"
Remove-AppxPackage -Package $AppPackageFullName -ErrorAction Stop | Out-Null
}
catch [System.Exception] {
Write-LogEntry -Value "Removing AppxPackage failed: $($_.Exception.Message)"
}
}
else {
Write-LogEntry -Value "Unable to locate AppxPackage for app: $($App.Name)"
}
# Attempt to remove AppxProvisioningPackage
if ($AppProvisioningPackageName -ne $null) {
try {
Write-LogEntry -Value "Removing application provisioning package: $($AppProvisioningPackageName)"
Remove-AppxProvisionedPackage -PackageName $AppProvisioningPackageName -Online -ErrorAction Stop | Out-Null
}
catch [System.Exception] {
Write-LogEntry -Value "Removing AppxProvisioningPackage failed: $($_.Exception.Message)"
}
}
else {
Write-LogEntry -Value "Unable to locate AppxProvisioningPackage for app: $($App.Name)"
}
}
}
# White list of Features On Demand V2 packages
Write-LogEntry -Value "Starting Features on Demand V2 removal process"
$WhiteListOnDemand = "NetFX3|Language|Browser.InternetExplorer"
# Get Features On Demand that should be removed
$OnDemandFeatures = Get-WindowsCapability -Online | Where-Object { $_.Name -notmatch $WhiteListOnDemand -and $_.State -like "Installed"} | Select-Object -ExpandProperty Name
foreach ($Feature in $OnDemandFeatures) {
try {
Write-LogEntry -Value "Removing Feature on Demand V2 package: $($Feature)"
Get-WindowsCapability -Online -ErrorAction Stop | Where-Object { $_.Name -like $Feature } | Remove-WindowsCapability -Online -ErrorAction Stop | Out-Null
}
catch [System.Exception] {
Write-LogEntry -Value "Removing Feature on Demand V2 package failed: $($_.Exception.Message)"
}
}
# Complete
Write-LogEntry -Value "Completed built-in AppxPackage and AppxProvisioningPackage removal process"Can someone point me in the right direction?
THANKS
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
-
olaplanche
- Messages: 178
- Registration: January 26, 2017 - 11:11
I solved my problem with the following code:
You need to enable PowerShell script execution on the affected machines or add the "-executionpolicy bypass" parameter
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
#import subprocess
uninstallkey = []
def install():
run('powershell.exe -NoProfile -NonInteractive -File RemoveBuiltinApps.ps1')- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
-
jeancharles
- Messages: 21
- Registration: June 11, 2019 - 10:02
Hello,
A bit late, but wouldn't it be better to modify the powershell command to add "-executionpolicy bypass" directly into the command?
A bit late, but wouldn't it be better to modify the powershell command to add "-executionpolicy bypass" directly into the command?
-
olaplanche
- Messages: 178
- Registration: January 26, 2017 - 11:11
Good morning,
That's exactly what I indicated in my sentence
:
That's exactly what I indicated in my sentence
You need to enable PowerShell script execution on the affected machines or add the "-executionpolicy bypass" parameter.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
-
jeancharles
- Messages: 21
- Registration: June 11, 2019 - 10:02
Ah yes, indeed, reading about it, that's it, 
I'm trying to go too fast and I'm forgetting half the information along the way!
Thank you!
I'm trying to go too fast and I'm forgetting half the information along the way!
Thank you!
