Powershell 从列表调用CIMMethod-SCCM应用程序安装

Powershell 从列表调用CIMMethod-SCCM应用程序安装,powershell,sccm,Powershell,Sccm,我使用以下命令从软件中心为最终用户在非强制应用程序上懒洋洋地安装SCCM应用程序,但在尝试跨多台计算机执行此操作时,它不起作用: $computer = Get-Content -Path c:\temp\computers.txt foreach ($computer in $computers) { $appName = 'AppNameHere' $Application = (Get-CimInstance -ClassName CCM_Application -Namespace

我使用以下命令从软件中心为最终用户在非强制应用程序上懒洋洋地安装SCCM应用程序,但在尝试跨多台计算机执行此操作时,它不起作用:

$computer = Get-Content -Path c:\temp\computers.txt
foreach ($computer in $computers) {

$appName = 'AppNameHere'

$Application = (Get-CimInstance -ClassName CCM_Application -Namespace "root\ccm\clientSDK" -ComputerName $computer | Where-Object {$_.Name -like $AppName})

$Args = @{EnforcePreference = [UINT32] 0
Id = "$($Application.id)"
IsMachineTarget = $Application.IsMachineTarget
IsRebootIfNeeded = $False
Priority = 'High'
Revision = "$($Application.Revision)" }

$Instance = @(Get-CimInstance -ClassName CCM_Application -Namespace "root\ccm\clientSDK" -ComputerName $Computer | Where-Object {$_.Name -like $AppName})
Invoke-CimMethod -Namespace ROOT\ccm\ClientSDK -ClassName CCM_Application -ComputerName $computer -MethodName Install -Arguments $Args | ft -AutoSize



}
如果我删除foreach,它将从列表中获取计算机,但只有当.txt包含一台计算机时才会处理。目前,它运行时不会出错,但不会执行任何操作,也不会产生任何输出。感觉我错过了一些非常明显的东西

我确实尝试过使用Invoke命令调用上面的命令,但它返回了大量的WS错误-我认为我们不需要使用Invoke方法调用它


非常感谢您的帮助-谢谢大家。

除了建议您将参数指定给不同于
$args
的变量,并修复
$computer=Get Content…
$computers
的拼写错误外,似乎还可以。亚伯拉罕,你是个英雄!这实际上只是$computers中的输入错误阻止了这个。。。我脑子都快发疯了。新鲜的眼睛总是有帮助的。非常感谢亚伯拉罕,感谢你的关注。