jeudi 28 mai 2020

Multiple foreach on if statement

I'm trying to rerun task-sequences on multiple computers from a Drop-Down list that contains the task-sequences names, and a computer list is loaded via a text file.

I tryed 2 diferent functions but the action isn't being triggered, no errors or output from ISE.

How can i achieve this?


#TaskSequences
$W10_PRELOAD_1809 ="W10_PRELOAD_1809"
$W10_UPG_1809 ="W10_UPG_1809"
$W10_UPG_1809_FORCE ="W10_UPG_1809_FORCE"

$Browse_OnClick= {
    $FileName = Select-FileDialog
    $Computers = Get-Content $FileName
    $Install.enabled = $true
}
$TaskSequence = "$W10_PRELOAD_1809","$W10_UPG_1809","$W10_UPG_1809_FORCE","$W7_CHECK_PRELOAD","$W7_1809_PRELOAD","$W7_UPG_1809","$W7_UPG_1809_FORCE"
$TaskSequence | % { $ListApps.Items.Add($_) }




$Install_OnClick={

    if (!$ListApps.SelectedItem) {[System.Windows.Forms.MessageBox]::Show("Please select a Task-Sequence from the drop down menu")

       }
    else {

        $TaskSequence = $ListApps.SelectedItem.ToString()

 foreach ($Computer in $Computers){

      if ($TaskSequence -eq "W10_PRELOAD_1809")
        {
           ([wmiclass]"\\$Computer\ROOT\ccm:SMS_Client").TriggerSchedule('PIC22459--PIC00024-6F6BCC28')
        }

        if ($TaskSequence -eq "W10_UPG_1809")
        {
            ([wmiclass]"\\$Computer\ROOT\ccm:SMS_Client").TriggerSchedule('PIC22505-PIC00026-6F6BCC28')
        }

        if ($TaskSequence -eq "W10_UPG_1809_FORCE")
        {
           ([wmiclass]"\\$Computer\ROOT\ccm:SMS_Client").TriggerSchedule('PIC22458-PIC00026-6F6BCC28')
        }

    }}}


$Install_OnClick2 ={
    foreach ($Computer in $Computers){
    foreach ($TaskSequence in $ListApps.SelectedItems)
    {   
        if ($TaskSequence -eq "W10_PRELOAD_1809")
        {
           ([wmiclass]"\\$Computer\ROOT\ccm:SMS_Client").TriggerSchedule('PIC22459--PIC00024-6F6BCC28')
        }

        if ($TaskSequence -eq "W10_UPG_1809")
        {
            ([wmiclass]"\\$Computer\ROOT\ccm:SMS_Client").TriggerSchedule('PIC22505-PIC00026-6F6BCC28')
        }

        if ($TaskSequence -eq "W10_UPG_1809_FORCE")
        {
           ([wmiclass]"\\$Computer\ROOT\ccm:SMS_Client").TriggerSchedule('PIC22458-PIC00026-6F6BCC28')
        }

    }
}}

Aucun commentaire:

Enregistrer un commentaire