Installing Windows 10 App with powershell remoting Installing Windows 10 App with powershell remoting powershell powershell

Installing Windows 10 App with powershell remoting


I was running into the exact same error. I was trying to install over Cygwin SSH instead of Powershell remoting, but I suspect the root cause is similar.

I was able to work around this by setting up a scheduled task which runs a Powershell script at a well-known location. (I made the scheduled task be run with the highest possible privileges, though I'm not sure if that's necessary.) I could then remotely set the contents of this Powershell script to run the app installation script, and then launch the scheduled task using schtasks, which worked like a charm.


I was stuck exactly in the same problem for a few days. After found this thread and read the Shoaib's answer, I started playing with scheduled tasks and finally write a script that works for me. I found a lot of problems with tasks and Add-AppxPackage and realize that you must configure the task with "User must be logged" option (sorry, spanish version). Add-AppxPackage needs the user must be logged to Works, which maybe explains why doesn't works with Invoke-Command.

$adminUser = "user@domain"$adminPass = "xxxxxxx"$pw = ConvertTo-SecureString -AsPlainText -Force -String $adminPass$cred = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList $adminUser, $pw$command = "Add-AppxPackage -Path '\\path\App.appxbundle'"$bytes = [Text.Encoding]::Unicode.GetBytes($command)$encodedCommand = [Convert]::ToBase64String($bytes)$remoteUser = "userLogged@domain"$remoteComputer = "192.168.0.50"$taskName = "Task"$taskCommand = "powershell.exe"$taskArg = "-noprofile -noninteractive -windowstyle hidden -executionpolicy bypass -encodedCommand ""$encodedCommand"""$taskAction = New-ScheduledTaskAction -Execute $taskCommand -Argument $TaskArg$taskTrigger = New-ScheduledTaskTrigger -At 9am -Once$taskPrincipal = New-ScheduledTaskPrincipal -UserID $remoteUser -LogonType Interactive -RunLevel Highest$cimSession = New-CimSession -ComputerName $remoteComputer -Credential $cred -Authentication NegotiateRegister-ScheduledTask -Action $taskAction -Trigger $tasktrigger -TaskName $taskName -Principal $taskPrincipal -CimSession $cimSessionStart-ScheduledTask -CimSession $cimSession -TaskName $taskNameSleep 5Get-ScheduledTask -CimSession $cimSession | Where-Object {$_.TaskName -eq $taskName} | Unregister-ScheduledTask -CimSession $cimSession -Confirm:$false


So yeah, as Shoaib already pointed out, scheduled task would do the trick. You could also try starting the remote process through WMI like so:

Invoke-WmiMethod -Class win32_process -name Create -ComputerName dflt -Credential $cred -ArgumentList "powershell.exe -noprofile -noninteractive -executionpolicy bypass -encodedCommand 'your encoded command goes here'" 

You could also try launching another powershell process from within ps session (supplying another users credentials) and passing command to that process (pretty similar to WMI method, but from PSSession).

Did you already try to just invoke-command on remote machine? that might work (althou I doubt it).

You could use Desired State Configuration to achieve what you need, but that's a bit overkill (but should work 101%). There's supposed to be a script provider for DSC.