How to run composite commands of powershell ?

Dani_S 4,501 Reputation points
2022-11-15T12:33:52.487+00:00

Hi,
As part of installing MAUI exe in server 2019, we need to run some commands in power shell as admin.
How we do it in **one command* in script file?
Thanks in advance,

1.Add-AppxProvisionedPackage -Online -PackagePath
C:\AutomationManager\DependenciesServer2019\Microsoft.DesktopAppInstaller_8
wekyb3d8bbwe.msixbundle -LicensePath
C:\AutomationManager\DependenciesServer2019\a941c144deac426082dc9f208f72
9138_License1.xml -Verbose
2. Add-AppxPackage -Path
"C:\AutomationManager\DependenciesServer2019\Microsoft.VCLibs.x64.14.00.Des
ktop.appx"
3. Add-AppxPackage -Path
"C:\AutomationManager\DependenciesServer2019\Microsoft.VCLibs.x86.14.00.Des
ktop.appx

Developer technologies .NET .NET MAUI
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-11-15T23:49:26.757+00:00

    Open notepad. Paste the commands into the window. Save the file as Something.ps1. From the Windows start menu search for powershell. Select "run as administrator". CD to the folder where you saved the file. Use the "dot slash" notation to execute the script, ",\Something.ps1" .

    If you are executing a .bat file that contains the commands to install maui, then add a line to call Powershell.

    powershell.exe -file C:\WhereverYouPutIt\Something.ps1"   
    

    Be sure to launch the bat file with "run as administrator".

    If you can't save a file, you can do it in one line by separating cmdlet's with the ";" character.

    powershell.exe -command "Add-AppxProvisionedPackage -Online -PackagePath C:\AutomationManager\DependenciesServer2019\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -LicensePath C:\AutomationManager\DependenciesServer2019\a941c144deac426082dc9f208f729138_License1.xml -Verbose; Add-AppxPackage -Path C:\AutomationManager\DependenciesServer2019\Microsoft.VCLibs.x64.14.00.Desktop.appx; Add-AppxPackage -Path C:\AutomationManager\DependenciesServer2019\Microsoft.VCLibs.x86.14.00.Desktop.appx"   
    
    0 comments No comments

  2. Hoekstra Jelle 501 Reputation points
    2022-11-16T14:37:36.7+00:00

    Hi!

    Regarding the content of the file, for ease of reuse and a bit of readability consider something like this:

    Provisioned AppxPackage

    Add-AppxProvisionedPackage -Online -PackagePath "C:\AutomationManager\DependenciesServer2019\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" `
    -LicensePath "C:\AutomationManager\DependenciesServer2019\a941c144deac426082dc9f208f729138_License1.xml" -Verbose

    Appxpackage list

    $appxpackagelist = "C:\AutomationManager\DependenciesServer2019\Microsoft.VCLibs.x64.14.00.Desktop.appx", "C:\AutomationManager\DependenciesServer2019\Microsoft.VCLibs.x86.14.00.Desktop.appx"

    Foreach loop for installing the Appxpackages

    foreach ($package in $appxpackagelist){
    Add-AppxPackage -Path $package
    }

    Regarding the execution you could follow the steps described by MotoX80

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.