我想通过PowerShell在服务器上安装特定包。
Get-WmiObject -Namespace ROOT\ccm\ClientSDK -Class CCM_Application -ComputerName Y31056 | Select-Object AllowedActions, Fullname
我可以列出服务器上安装或未安装的软件。 所以我想在软件中心只安装特定的软件包。
AllowedActions Fullname
-------------- --------
{Install} CMTrace
{Install} SCCMpackageV1
{Install} SQL Server 2014 SP2
我想运行脚本来通过powershell安装SCCMpackageV1,但有点混淆如何实现它。
$SoftwareApp = Get-WmiObject -Namespace ROOT\ccm\ClientSDK -Class CCM_Application -ComputerName Y31056 | Select-Object AllowedActions, Fullname
$SoftwareApp.install.SCCMpackageV1
我认为简单的安装命令应该可行,但我没有收到任何输出。软件也没有安装。
答案 0 :(得分:1)
The Install method for CCM_Application objects needs parameters to be supplied. Microsoft official document contains really detailed information regarding each parameter and you can refer below link: https://msdn.microsoft.com/en-us/library/jj902785.aspx
See below code as an example to install application on client machine:
$ComputerName = "Y31056"
$AppName = "SCCMPackageV1"
$s = New-PSSession -ComputerName $ComputerName
Invoke-Command -Session $s -Argu $ComputerName,$AppName -ScriptBlock `
{
param ($ComputerName,$AppName)
write-host "Getting Parameters for '$AppName' on $ComputerName"
$Application = Get-WmiObject -computername $ComputerName -Namespace "root\ccm\ClientSDK" -Class CCM_Application | where {$_.Name -like "$AppName"} | Select-Object Id, Revision, IsMachineTarget
$AppID = $Application.Id
$AppRev = $Application.Revision
$AppTarget = $Application.IsMachineTarget
([wmiclass]'ROOT\ccm\ClientSdk:CCM_Application').Install($AppID, $AppRev, $AppTarget, 0, 'Normal', $False) | Out-Null
}
Remove-PSSession $s