Seite 1 von 1

[GELÖST] Wie führt man ein PowerShell-Skript aus?

Veröffentlicht: 11. Dez. 2017 - 14:57 Uhr
von olaplanche
Hallo,

ich muss ein PowerShell-Skript aus einem Paket ausführen, um nach einem Upgrade unnötige Apps von Windows 10 zu entfernen.
Ich habe dazu bereits einige Forenbeiträge gefunden, aber die Vorgehensweise ist unterschiedlich.

Gibt es eine elegantere Lösung?

Zur Information:
- Installierte WAPT-Version: 1.3.13
- Server-Betriebssystem: Debian Jessie
- Betriebssystem des Administrations-/Paketerstellungsrechners: Windows 10.

Vielen Dank.

Betreff: Ausführen eines PowerShell-Skripts?

Veröffentlicht: 13. Dez. 2017 - 12:31 Uhr
von Sfonteneau
Verwenden Sie die Funktion run_powershell

Zum Beispiel :

Code: Alle auswählen

run_powershell('Get-AppxPackage -Name Microsoft.Windows.Cortana -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}')
Es ist am saubersten

Betreff: Ausführen eines PowerShell-Skripts?

Veröffentlicht: 13. Dez. 2017 - 16:06 Uhr
von olaplanche
Hallo und vielen Dank für die Antwort.

Ich teste derzeit mit folgendem Paket:

Code: Alle auswählen

# -*- 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')
Nur der mittlere Befehl scheint zu funktionieren (mit einem neuen Benutzerkonto gibt es keine Probleme). Ich finde keine Informationen zur Funktion `run_powershell`; gibt es eine Möglichkeit, wie in der PowerShell-Konsole, Feedback zu erhalten? Die Wapt-Konsole meldet keine Fehler, trotzdem werden die Apps nicht vom Administratorkonto entfernt!

DANKE

Betreff: Ausführen eines PowerShell-Skripts?

Veröffentlicht: 14. Dez. 2017 - 13:51 Uhr
von olaplanche
Zusätzliche Information:

Ich verwende die x64-Version von PowerShell, und dies könnte an den Einschränkungen dieser Version für das Systemkonto liegen.

Betreff: Ausführen eines PowerShell-Skripts?

Veröffentlicht: 18. Oktober 2018 – 13:07 Uhr
von olaplanche
Guten Morgen,

Ich bringe dieses Problem erneut zur Sprache, da ich es immer noch nicht gelöst habe.
In der Zwischenzeit hat sich einiges verändert, nämlich:

- Installierte WAPT-Version: 1.6.2.7
- Server-Betriebssystem: Debian Stetch
- Betriebssystem des Administrations-/Paketerstellungsrechners: Windows 10

Als Nächstes verwende ich während meiner MDT-Bereitstellung ein neues Skript; hier ist es:

Code: Alle auswählen

    # 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"
Ich würde es gerne in einem wapt-Paket verwenden, aber ich weiß nicht wie...
Kann mir jemand den richtigen Weg weisen?

DANKE

Betreff: Ausführen eines PowerShell-Skripts?

Veröffentlicht: 19. Dez. 2018 - 10:12 Uhr
von olaplanche
Ich habe mein Problem mit folgendem Code gelöst:

Code: Alle auswählen

# -*- coding: utf-8 -*-
from setuphelpers import *
#import subprocess

uninstallkey = []

def install():
    run('powershell.exe -NoProfile -NonInteractive -File RemoveBuiltinApps.ps1')
Sie müssen die Ausführung von PowerShell-Skripten auf den betroffenen Rechnern aktivieren oder den Parameter "-executionpolicy bypass" hinzufügen

Betreff: [GELÖST] Ein PowerShell-Skript ausführen?

Veröffentlicht: 15. Oktober 2019 - 11:45 Uhr
von Jeancharles
Hallo,

etwas spät, aber wäre es nicht besser, den PowerShell-Befehl so zu ändern, dass "-executionpolicy bypass" direkt in den Befehl eingefügt wird?

Betreff: [GELÖST] Ein PowerShell-Skript ausführen?

Veröffentlicht: 15. Oktober 2019 - 12:00 Uhr
von olaplanche
Guten Morgen,

Das ist genau das, was ich in meinem Satz angedeutet habe ;) :
Sie müssen die Ausführung von PowerShell-Skripten auf den betroffenen Rechnern aktivieren oder den Parameter "-executionpolicy bypass" hinzufügen.

Betreff: [GELÖST] Ein PowerShell-Skript ausführen?

Veröffentlicht: 15. Oktober 2019 - 12:04 Uhr
von Jeancharles
Ah ja, genau, beim Lesen merke ich, dass :)
ich zu schnell vorgehe und dabei die Hälfte der Informationen vergesse!

Danke!