Página 1 de 1
[RESUELTO] ¿Cómo ejecutar un script de PowerShell?
Publicado: 11 de diciembre de 2017 - 14:57
por olaplanche
Hola,
necesito ejecutar un script de PowerShell desde un paquete (para eliminar aplicaciones innecesarias de Windows 10 después de una actualización).
He encontrado varias publicaciones en foros sobre esto, ¡pero todas lo abordan de manera diferente! ¿
Existe una solución más sencilla?
Para su información:
- Versión de WAPT instalada: 1.3.13
- Sistema operativo del servidor: Debian Jessie
- Sistema operativo de la máquina de administración/creación de paquetes: Windows 10
Gracias
Re: ¿Ejecutar un script de PowerShell?
Publicado: 13 de diciembre de 2017 - 12:31
por sfonteneau
utilice la función run_powershell
Por ejemplo :
Código: Seleccionar todo
run_powershell('Get-AppxPackage -Name Microsoft.Windows.Cortana -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}')
Es el más limpio
Re: ¿Ejecutar un script de PowerShell?
Publicado: 13 de diciembre de 2017 - 16:06
por olaplanche
Hola y gracias por la respuesta.
Actualmente estoy probando con el siguiente paquete:
Código: Seleccionar todo
# -*- 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 el comando intermedio parece funcionar (sin problemas con una cuenta de usuario nueva). No encuentro información sobre la función `run_powershell`; ¿es posible obtener información como en la consola de PowerShell? La consola de Wapt no informa de ningún error, pero las aplicaciones no se eliminan de la cuenta de administrador
GRACIAS
Re: ¿Ejecutar un script de PowerShell?
Publicado: 14 de diciembre de 2017 - 13:51
por olaplanche
Información adicional:
Estoy utilizando la versión x64 de PowerShell y esto podría deberse a limitaciones de la misma para la cuenta del sistema.
Re: ¿Ejecutar un script de PowerShell?
Publicado: 18 de octubre de 2018 - 13:07
por olaplanche
Buen día,
Vuelvo a plantear este problema porque todavía no lo he solucionado.
Entretanto han cambiado bastantes cosas, a saber:
- Versión WAPT instalada: 1.6.2.7
- Sistema operativo del servidor: Debian Stetch
- Sistema operativo de la máquina de administración/creación de paquetes: Windows 10
A continuación, uso un nuevo script durante mi implementación de MDT; aquí está:
Código: Seleccionar todo
# 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"
Me gustaría usarlo en un paquete wapt, pero no veo cómo...
¿Puede alguien indicarme la dirección correcta?
GRACIAS
Re: ¿Ejecutar un script de PowerShell?
Publicado: 19 de diciembre de 2018 - 10:12
por olaplanche
Resolví mi problema con el siguiente código:
Código: Seleccionar todo
# -*- coding: utf-8 -*-
from setuphelpers import *
#import subprocess
uninstallkey = []
def install():
run('powershell.exe -NoProfile -NonInteractive -File RemoveBuiltinApps.ps1')
Debe habilitar la ejecución del script de PowerShell en las máquinas afectadas o agregar el parámetro "-executionpolicy bypass"
Re: [RESUELTO] ¿Ejecutar un script de PowerShell?
Publicado: 15 de octubre de 2019 - 11:45 a. m.
por jeancharles
Hola,
un poco tarde, pero ¿no sería mejor modificar el comando de PowerShell para agregar "-executionpolicy bypass" directamente al comando?
Re: [RESUELTO] ¿Ejecutar un script de PowerShell?
Publicado: 15 de octubre de 2019 - 12:00 p. m.
por olaplanche
Buen día,
Eso es exactamente lo que indiqué en mi frase

:
Debe habilitar la ejecución de scripts de PowerShell en las máquinas afectadas o agregar el parámetro "-executionpolicy bypass".
Re: [RESUELTO] ¿Ejecutar un script de PowerShell?
Publicado: 15 de octubre de 2019 - 12:04 p. m.
por jeancharles
Ah, sí, efectivamente, al leer sobre ello, ¡eso es!

Estoy intentando ir demasiado rápido y se me olvida la mitad de la información por el camino. ¡
Gracias!