Script de rafraichissement des clients SCCM


Le script ci dessous, récupéré chez un client (merci Pascal!!!) permet de lancer toutes les actions disponibles dans le client SCCM afin de forcer la récupération des stratégies, envoyer l’inventaire logiciel et matériel, etc…

Très très pratique Sourire

 

 # DECLARATION DE FONCTIONS

Function Get-Actions($actions){
    $actions | select Name 
}

Function Execute-Action($actions,$name){
    [ARRAY]$actionToPerform = $null
    
    if(($name -eq "all") -AND ($actions -ne $null)){
        foreach($action in $actions){
            $actionToPerform += $action
        }
    }
    else {
        $actionToPerform += $actions | ?{$_.Name -like $name} 
    }
    if($actionToPerform -ne $null){
        foreach($action in $actionToPerform) {
            Write-Host (">> Executing : " + ($action.Name))
            $action.PerformAction()
        }
    }
    else {
        Write-Host "Unable to run client action : $name"
    }

}

function Get-AllActions ($actions){
    Execute-Action $actions "all"
}
function Get-MachinePolicy ($actions){
    Execute-Action $actions "*Machine Policy"
}

Function Get-UserPolicy ($actions){
    Execute-Action $actions "*User Policy"
}

Function Update-CollectionCycle ($actions){
    Execute-Action $actions "*Collection Cycle"
}

Function Update-MSI ($actions){
    Execute-Action $actions "MSI*"
}
Function Update-WSUS ($actions){
    Execute-Action $actions "Software Updates*"
}
Function Update-Source ($actions){
    Execute-Action $actions "Updates Source*"
}
Function Report-SoftwareMetering ($actions){
    Execute-Action $actions "Software Metering*"
}


Function Execute-Action($actions,$name){
    [ARRAY]$actionToPerform = $null
    
    if(($name -eq "all") -AND ($actions -ne $null)){
        foreach($action in $actions){
            $actionToPerform += $action
        }
    }
    else {
        $actionToPerform += $actions | ?{$_.Name -like $name} 
    }
    if($actionToPerform -ne $null){
        foreach($action in $actionToPerform) {
            Write-Host (">> Executing : " + ($action.Name))
            $action.PerformAction()
        }
    }
    else {
        Write-Host "Unable to run client action : $name"
    }

}


# -----------------------------------------------------
# UPDATE SCCM TO RUN
# -----------------------------------------------------
$sms_client = New-Object -COM 'CPApplet.CPAppletMgr'
$actions = $sms_client.GetClientActions()

Write-host -FORE RED "# -----------------------------------------------------"
Write-host -FORE RED ("# UPDATING SCCM CLIENT " + (get-date -uFormat "%Y %H:%M:%S"))
Write-host -FORE RED "# -----------------------------------------------------"
Write-host -FORE RED "    "

Get-AllActions $actions

 

A propos Red Kaffe

IT Trainer and Consultant on Microsoft Technologies. Windows Server and Client, Service Center 2012, WSUS/MDT/ADK/WAIK, SBS 2008/2011, Office 365, etc. Fully dedicated to support and train my customers...
Cet article, publié dans Cloud, Deployment, Scripting, System Center, est tagué , , . Ajoutez ce permalien à vos favoris.

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l’aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s