dispatcher
Goto Top

Powershell: Software Installationen im SCCM Manager starten

Hallo Zusammen,

ich habe folgendes Skript...
Function Invoke-AppInstallation  
{  
[CmdletBinding()]  
Param  
(  
  
 [String][Parameter(Mandatory=$True, Position=1)] $Computername,  
 [String][Parameter(Mandatory=$True, Position=2)] $AppName,  
 [ValidateSet("Install","Uninstall")]    
 [String][Parameter(Mandatory=$True, Position=3)] $Method  
)  
   
Begin {  
$Application = (Get-CimInstance -ClassName CCM_Application -Namespace "root\ccm\clientSDK" -ComputerName $Computername | Where-Object {$_.Name -like $AppName})    
   
$Args = @{EnforcePreference = [UINT32] 0  
Id = "$($Application.id)"    
IsMachineTarget = $Application.IsMachineTarget  
IsRebootIfNeeded = $False  
Priority = 'High'    
Revision = "$($Application.Revision)" }    
   
}  
   
Process  
   
{  
   
Invoke-CimMethod -Namespace "root\ccm\clientSDK" -ClassName CCM_Application -ComputerName $Computername -MethodName $Method -Arguments $Args    
   
}  
   
End {}  
   
}
Dieses startet die Installation eines bestimmten verfügbaren Softwarepakets im SCCM an. Ich muss aber immer den Namen des Pakets mit angeben.
Es sollen aber alle verfügbaren Installationen gestartet werden. Gibt es da eine Möglichkeit?

Content-Key: 621108

Url: https://administrator.de/contentid/621108

Ausgedruckt am: 29.03.2024 um 13:03 Uhr

Mitglied: 146189
Lösung 146189 10.11.2020 aktualisiert um 12:22:37 Uhr
Goto Top
Where-Object weglassen und mit nem Foreach über das Ergebnis von Get-CimInstance itterieren, z.B. so
Function Invoke-AppInstallation {  
    [CmdletBinding()]  
    Param(
     [Parameter(Mandatory=$True, Position=1)][string]$Computername,
     [Parameter(Mandatory=$True, Position=2)][ValidateSet("Install","Uninstall")][string]$Method    
    )

    Get-CimInstance -ClassName CCM_Application -Namespace "root\ccm\clientSDK" -ComputerName $Computername | %{     
        $arguments = @{
            EnforcePreference = [UINT32] 0  
            Id = "$($_.id)"    
            IsMachineTarget = $_.IsMachineTarget  
            IsRebootIfNeeded = $False  
            Priority = 'High'    
            Revision = $_.Revision
        }  
   
        Invoke-CimMethod -Namespace "root\ccm\clientSDK" -ClassName CCM_Application -ComputerName $Computername -MethodName $Method -Arguments $arguments  
    }
}
Mitglied: dispatcher
dispatcher 10.11.2020 um 20:22:32 Uhr
Goto Top
Hätte ich auch selbst drauf kommen können face-smile hatte es zwar schon ohne "where-object" probiert aber ohne for-each schleife.
Funktioniert bestens.
Vielen Dank