Pagina 1 di 1
[RISOLTO] Come eseguire uno script PowerShell?
Pubblicato: 11 dicembre 2017 - 14:57
di olaplanche
Salve,
devo eseguire uno script PowerShell da un pacchetto (per rimuovere le app non necessarie da Windows 10 dopo un aggiornamento).
Ho trovato diverse discussioni sui forum a riguardo, ma ognuna propone una soluzione diversa!
Esiste un metodo più pulito?
Per vostra informazione:
- Versione di WAPT installata: 1.3.13
- Sistema operativo del server: Debian Jessie
- Sistema operativo della macchina di amministrazione/creazione del pacchetto: Windows 10
Grazie
Re: Eseguire uno script PowerShell?
Pubblicato: 13 dicembre 2017 - 12:31
di sfontenau
utilizzare la funzione run_powershell
Per esempio :
Codice: Seleziona tutto
run_powershell('Get-AppxPackage -Name Microsoft.Windows.Cortana -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}')
È il più pulito
Re: Eseguire uno script PowerShell?
Pubblicato: 13 dicembre 2017 - 16:06
di olaplanche
Ciao e grazie per la risposta.
Al momento sto testando il seguente pacchetto:
Codice: Seleziona tutto
# -*- 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')
Solo il comando intermedio sembra funzionare (nessun problema con un nuovo account utente). Non riesco a trovare nulla sulla funzione `run_powershell`; è possibile ottenere feedback come nella console di PowerShell? La console di Wapt non segnala errori, eppure le app non vengono rimosse dall'account amministratore!
GRAZIE
Re: Eseguire uno script PowerShell?
Pubblicato: 14 dicembre 2017 - 13:51
di olaplanche
Informazioni aggiuntive:
sto utilizzando la versione x64 di PowerShell e questo potrebbe essere dovuto a limitazioni per l'account di sistema.
Re: Eseguire uno script PowerShell?
Pubblicato: 18 ottobre 2018 - 13:07
di olaplanche
Buongiorno,
Ripropongo questo problema, perché non l'ho ancora risolto.
Nel frattempo sono cambiate parecchie cose, in particolare:
- Versione WAPT installata: 1.6.2.7
- Sistema operativo del server: Debian Stetch
- Sistema operativo della macchina di amministrazione/creazione pacchetti: Windows 10
Successivamente, utilizzo un nuovo script durante la distribuzione MDT; eccolo:
Codice: Seleziona tutto
# 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"
Vorrei utilizzarlo in un pacchetto wapt, ma non vedo come...
Qualcuno può indicarmi la giusta direzione?
GRAZIE
Re: Eseguire uno script PowerShell?
Pubblicato: 19 dicembre 2018 - 10:12
di olaplanche
Ho risolto il mio problema con il seguente codice:
Codice: Seleziona tutto
# -*- coding: utf-8 -*-
from setuphelpers import *
#import subprocess
uninstallkey = []
def install():
run('powershell.exe -NoProfile -NonInteractive -File RemoveBuiltinApps.ps1')
È necessario abilitare l'esecuzione dello script PowerShell sui computer interessati oppure aggiungere il parametro "-executionpolicy bypass"
Re: [RISOLTO] Eseguire uno script PowerShell?
Pubblicato: 15 ottobre 2019 - 11:45
di jeancharles
Ciao,
un po' in ritardo, ma non sarebbe meglio modificare il comando PowerShell aggiungendo "-executionpolicy bypass" direttamente al comando?
Re: [RISOLTO] Eseguire uno script PowerShell?
Pubblicato: 15 ottobre 2019 - 12:00
di olaplanche
Buongiorno,
È esattamente ciò che ho indicato nella mia frase

:
È necessario abilitare l'esecuzione degli script PowerShell sui computer interessati oppure aggiungere il parametro "-executionpolicy bypass".
Re: [RISOLTO] Eseguire uno script PowerShell?
Pubblicato: 15 ottobre 2019 - 12:04
di jeancharles
Ah sì, certo, leggendo a riguardo, è proprio questo il problema:

sto cercando di andare troppo veloce e mi dimentico metà delle informazioni lungo la strada!
Grazie!