private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { softwaredistribution.CCM_SoftwareDistribution oSW = ((DataGrid)e.OriginalSource).SelectedItem as softwaredistribution.CCM_SoftwareDistribution; System.Collections.ObjectModel.ObservableCollection <wmiProp> oColl = new System.Collections.ObjectModel.ObservableCollection <wmiProp>(); oSW._RawObject.Properties.Where(w => w.GetType() == typeof(PSProperty) & !w.Name.StartsWith("_")).ToList().ForEach(x => oColl.Add(new wmiProp(x.Name, x.Value, x.TypeNameOfValue))); //softwaredistribution.CCM_Scheduler_ScheduledMessage oSchedule = oSW._ScheduledMessage(); dataGrid2.BeginInit(); dataGrid2.ItemsSource = oColl; dataGrid2.EndInit(); } catch { } }
// Method to trigger an already advertised task sequence immediatly. public static void TSTrigger(string Hostname, string TSName) { // Initilize some variables that we will need later on. softwaredistribution.CCM_SoftwareDistribution selectedAdvert = null; // Connects to the SCCM Agent on the target machine. SCCMAgent oAgent = ConnectAgent(Hostname); // Adds all adverts available on target to a list. var allAdverts = oAgent.Client.SoftwareDistribution.Advertisements_(true); Console.WriteLine("The host '" + Hostname + "' has the following advertisements assigned to it:"); //Console.WriteLine("------------------------------"); // Loops through all the adverts and 1) Prints them; 2) Selects the targeted advert via the supplied TSName var and prepares it to be triggered. foreach (softwaredistribution.CCM_SoftwareDistribution adv in allAdverts) { Console.WriteLine("--> " + adv.PKG_Name); if (adv.PKG_Name == TSName) { selectedAdvert = adv; } } Console.WriteLine(); // Shows the selected advert if it exists, catches the error if it doesn't. try { Console.WriteLine("The following advertisement has been selected for install:"); Console.WriteLine("--> " + selectedAdvert.PKG_Name); Console.WriteLine(); } catch { Console.WriteLine("<ERROR> The advertisment '" + TSName + "' was not found!"); System.Environment.Exit(1); } // Sets the selected advert to immediatly start. Console.WriteLine("Triggering " + selectedAdvert.PKG_Name + "..."); selectedAdvert.TriggerSchedule(true); Console.WriteLine("Advertisment '" + selectedAdvert.PKG_Name + "' triggered."); Console.WriteLine(); }