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, $Install_OnClick and $Install_OnClick2, but the action isn't being triggered, no errors or output from ISE, i'm using a Powershell GUi with a Combobox/Drop-Down List
How can i achieve this?
Thank you
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')
}
}
}
}
'Les tests, c'est pour ceux qui ne savent pas coder'
Multiple foreach on if statement
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.