3

How can I run the following command in a batch file?

POWERSHELL -Command "& {Get-AppxPackage | %% { Add-AppxPackage -ForceApplicationShutdown -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppxManifest.xml" -verbose }}"

Every time I try it I get an error:

Add-AppxPackage : A positional parameter cannot be found that accepts argument '\AppxManifest.xml'.
At line:1 char:25
+ ... ackage | % {Add-AppxPackage -ForceApplicationShutdown -DisableDevelop ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-AppxPackage], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

1 Answers1

3

Well your command is still inside a batch file so the special batch characters must be escape. I always use this site it is a pretty good overview.

https://www.robvanderwoude.com/escapechars.php

From personal experience I would always choose to put the command in a file if it there is too much escaping needed.

Powershell.exe -ExecutionPolicy Bypass -File yourscript.ps1
Carsten.R
  • 66
  • 6