使用PowerShell远程安装Windows 10应用程序

6
我一直在尝试使用PowerShell远程安装Windows 10通用应用程序,但始终无法成功。我已经尝试了一切我能想到的方法,现在我转向你寻求答案或解释为什么我的方法不起作用。如果有其他替代方案也将不胜感激。
本质上,我想做的是能够远程安装Windows 10应用程序,我的方法包括下载文件到目标计算机并使用PowerShell远程运行安装程序。这是我的脚本的简化版本:
$computerName = 'XYZ'
$userName = 'abc'
$newCred = Get-Credential "$computerName\$userName"
$newSession = New-PSSession -ComputerName $computerName -Credential $newCred -ErrorAction Stop
Invoke-Command -Session $newSession -ErrorAction Stop -Verbose -Scriptblock {   

function installApp($srcDirectory) {
     $installer = Get-ChildItem "$srcDirectory\App.Test*\Add-AppDevPackage.ps1" | Select-Object -ExpandProperty FullName        
     &($installer)             
}

$srcDirectory =  "$($env:TEMP)/TestApp"
    installApp($srcDirectory)
}

Remove-PSSession $newSession

它实际上仅尝试运行在Visual Studio中生成的脚本以安装应用程序。但当我运行它时,我会得到以下结果:

Installing app...

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF6, Det gick inte att registrera paketet.

error 0x80070005: Adding a tile failed with unexpected error.

NOTE: For additional information, look for [ActivityId] a3f9b89b-3292-000113ea-f9a39232d101 in the Event Log or use the command line Get-AppxLog -ActivityID a3f9b89b-3292-0001-13ea-f9a39232d101

At  C:\Users\abc\AppData\Local\Temp\App\TestApp_1_0_0\Add-AppDevPackage.ps 1:392 char:13
+             Add-AppxPackage -Path $DeveloperPackagePath.FullName -
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          :     (C:\Users\abc..._arm.appxbundle:String) [Add-AppxPackage], IOException
+ FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

Error: Could not install the app.

运行 Get-AppxLog -ActivityID a3f9b89b-3292-0001-13ea-f9a39232d101 命令的输出如下:

Time                      ID           Message                                                                                                                          
----                      --           -------                                                                                                                          
2015-12-10 10:45:39       301          The calling process is wsmprovhost.exe                                                                                           
2015-12-10 10:45:39       603          Started deployment Add operation on a package with main parameter: Test.App_1.1.1.0_x86_x64_arm.appxbundle and Options: Fo
                                       rceApplicationShutdownOption. See http://go.microsoft.com/fwlink/?LinkId=235160 for help diagnosing app deployment issues.       
2015-12-10 10:45:40       164          The app bundle signature was validated for core content of the app bundle published by CN=xxx. App packages won't be validated 
                                       until they are read.                                                                                                             
2015-12-10 10:45:40       391          The bundle streaming reader was created successfully for bundle 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutra
                                       l_~_m042xdac27ax6.                                                                                                               
2015-12-10 10:45:40       10002        Creating Resiliency File C:\ProgramData\Microsoft\Windows\AppRepository\d195e8d8-35c4-4b85-bb4f-d99c525791c1_S-1-5-21-3220428687-
                                       2095128414-3811769907-1077_1.rslc for Add Operation on Package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutral
                                       _~_m042xdac27ax6.                                                                                                                
2015-12-10 10:45:40       607          Deployment Add operation on package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutral_~_m042xdac27ax6 has been d
                                       e-queued and is running for user XYZ\abc.                                                                    
2015-12-10 10:45:40       613          Adding uri to the list of Uris: file:///C:/Users/abc/AppData/Local/Temp/TestApp/Test.App_1
                                       .1.1.0_Test/Test.App_1.1.1.0_x86_x64_arm.appxbundle.                                                                      
2015-12-10 10:45:40       614          Bundle Uri file:///C:/Users/abc/AppData/Local/Temp/TestApp/Test.App_1.1.1.0_Test/Artologik
                                       .Kiosk_1.1.1.0_x86_x64_arm.appxbundle contains packages: "Test.App_1.1.1.0_x86.appx": 588388d0-5c5f-41e1-8965-f8ed6a2644.TestApp
                                       _1.1.1.0_x86__m042xdac27ax6 "Test.App_1.1.1.0_x64.appx": 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_
                                       1.1.1.0_x64__m042xdac27ax6 "Test.App_1.1.1.0_ARM.appx": 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_arm__m0
                                       42xdac27ax6.                                                                                                                     
2015-12-10 10:45:40       157          The app package signature was validated for core content of the app package published by CN=xxx. Payload won't be validated unt
                                       il the files are read.                                                                                                           
2015-12-10 10:45:40       170          The streaming reader was created successfully for app package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_x86__m04
                                       2xdac27ax6.                                                                                                                      
2015-12-10 10:45:40       613          Adding uri to the list of Uris: file:///C:/Users/abc/AppData/Local/Temp/TestApp/Test.App_1
                                       .1.1.0_Test/Test.App_1.1.1.0_x86_x64_arm.appxbundle\Test.App_1.1.1.0_x86.appx.                                     
2015-12-10 10:45:41       446          GetFullyQualifiedReference from the Main Resource Map for package full name: 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1
                                       .1.1.0_x86__m042xdac27ax6 and reference string: Test.App failed.                                                          
2015-12-10 10:45:41       446          GetFullyQualifiedReference from the Main Resource Map for package full name: 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1
                                       .1.1.0_x86__m042xdac27ax6 and reference string: xxx failed.                                                                    
2015-12-10 10:45:41       446          GetFullyQualifiedReference from the Main Resource Map for package full name: 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1
                                       .1.1.0_x86__m042xdac27ax6 and reference string: Test.App failed.                                                          
2015-12-10 10:45:41       446          GetFullyQualifiedReference from the Main Resource Map for package full name: 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1
                                       .1.1.0_x86__m042xdac27ax6 and reference string: Test.App failed.                                                          
2015-12-10 10:45:41       446          GetFullyQualifiedReference from the Main Resource Map for package full name: 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1
                                       .1.1.0_x86__m042xdac27ax6 and reference string: default.html failed.                                                             
2015-12-10 10:45:42       10000        About to service package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_x86__m042xdac27ax6. Setting the package state
                                        to disabled returned with 0x80070490.                                                                                           
2015-12-10 10:45:42       827          Capability parsing started for the package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_x86__m042xdac27ax6         
2015-12-10 10:45:42       5060         error 0x80070005: Adding a tile failed with unexpected error.                                                                    
2015-12-10 10:45:42       303          error 0x80070005: While preparing to process the request, the system failed to register the windows.visualElements extension due 
                                       to the following error: Access is denied.                                                                                           
                                       .                                                                                                                                
2015-12-10 10:45:42       300          error 0x80070005: Cannot register the 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_m042xdac27ax6 package due to the followi
                                       ng error: Access is denied.                                                                                                         
                                       .                                                                                                                                
2015-12-10 10:45:42       605          The last successful state reached was ResolvedDeferredRegistrations. Failure occurred before reaching the next state Registration
                                       Changed.                                                                                                                         
2015-12-10 10:45:42       472          Moving package folder \\?\C:\Program Files\WindowsApps\588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutral_~_m042x
                                       dac27ax6 to \\?\C:\Program Files\WindowsApps\Deleted\588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutral_~_m042xda
                                       c27ax67380de84-c8fa-4c14-a532-e6f2a1242a48. Result: 0x0.                                                                         
2015-12-10 10:45:42       472          Moving package folder \\?\C:\Program Files\WindowsApps\588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_x86__m042xdac27
                                       ax6 to \\?\C:\Program Files\WindowsApps\Deleted\588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_x86__m042xdac27ax60605
                                       8072-2034-461b-a9ba-a085b10152a7. Result: 0x0.                                                                                   
2015-12-10 10:45:42       10001        Finished servicing package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_x86__m042xdac27ax6. Setting the package sta
                                       te to enabled returned with 0x0.                                                                                                 
2015-12-10 10:45:42       401          Deployment Add operation with target volume C: on Package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutral_~_m0
                                       42xdac27ax6 from:  (Test.App_1.1.1.0_x86_x64_arm.appxbundle)  failed with error 0x80073CF6. See http://go.microsoft.com/fw
                                       link/?LinkId=235160 for help diagnosing app deployment issues.                                                                   
2015-12-10 10:45:42       404          AppX Deployment operation failed for package 588388d0-5c5f-41e1-8965-f8ed6a2644.Test.App_1.1.1.0_neutral_~_m042xdac27ax6 w
                                       ith error 0x80073CF6. The specific error text for this failure is: error 0x80070005: Adding a tile failed with unexpected error.

非常感谢提供的任何帮助。我是认真的!无论是建议、解决方法、异教仪式还是水晶...


在第一个失败点,您会收到“访问被拒绝”的错误。正在登录并运行脚本的本地用户是否具有在系统上安装应用程序的完全权限?即:不是受限/本地用户? - gravity
在我的情况下,我使用的帐户具有管理员权限。我尝试使用ProcMon查看拒绝访问错误来自何处,但是我只能看到一些注册表键的查询,而该帐户具有完全控制访问权限。 - Shoaib
3个回答

3
我遇到了完全相同的错误。我试图在Cygwin SSH上安装,而不是使用Powershell远程,但我认为根本原因是相似的。
我通过设置一个定期运行位于已知位置的Powershell脚本的计划任务来解决了这个问题。(我让计划任务以可能的最高权限运行,尽管我不确定是否必要。)然后,我可以远程设置此Powershell脚本的内容以运行应用程序安装脚本,然后使用启动计划任务,效果非常好。

我不是楼主,但我设置了悬赏,并且你建议的方法有效。 - Sam I am says Reinstate Monica

1
我曾经遇到了同样的问题,卡在那里好几天。在找到这个帖子并阅读Shoaib的回答后,我开始尝试使用计划任务,并最终编写了一个适合我的脚本。 我发现任务和Add-AppxPackage存在很多问题,并意识到您必须使用“用户必须登录”选项配置任务(抱歉,这是西班牙语版本)。Add-AppxPackage需要用户必须登录才能正常工作,这也许可以解释为什么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 Negotiate

Register-ScheduledTask -Action $taskAction -Trigger $tasktrigger -TaskName $taskName -Principal $taskPrincipal -CimSession $cimSession

Start-ScheduledTask -CimSession $cimSession -TaskName $taskName

Sleep 5

Get-ScheduledTask -CimSession $cimSession | Where-Object {$_.TaskName -eq $taskName} | Unregister-ScheduledTask -CimSession $cimSession -Confirm:$false

0

是的,正如Shoaib已经指出的那样,计划任务可以解决问题。您还可以尝试通过WMI启动远程进程,方法如下:

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

您也可以尝试在ps会话中启动另一个powershell进程(提供另一个用户的凭据),并将命令传递给该进程(与WMI方法非常相似,但来自PSSession)。

您是否已经尝试在远程计算机上使用invoke-command?那可能会起作用(虽然我怀疑)。

您可以使用期望状态配置来实现所需的内容,但这有点过度(但应该可以100%工作)。 DSC应该有一个脚本提供程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接