1

I am trying to create a runbook in SCCM that will list a the group in an OU then be able to select it and then add that user to the group. The process in the runbook is this currently. 1. enter user name then hit enter 2. opens up a drop down menu that will list the groups in the "applications" OU. (yes, that is the name of the OU) and click on "select" 3. then the user will get added to the proper group.

currently, I have a powershell form written that almost works, but I believe I am hitting the SCCM bug of wanting to only use powershell 2.0. I am getting a return of the distinguished name is not valid. I do have it hard coded into the form of what the DNs are and I verified my context is correct. I was advised to rewrite the whole procedure in C#. My only problem is that I haven't had the need to use or look at the code formatting. I know I am mostly self taught out of necessity so if I say something incorrectly, please forgive me.

Herculeon
  • 19
  • 4
  • What have you tried, and how has what you've tried failed? Ideally, you should provide a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. SO is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See [How to Ask a Good Question](http://stackoverflow.com/help/how-to-ask). – Jeff Zeitlin May 12 '17 at 19:21
  • Well, the runbook requires the username field, it passes that information to the .Net script (I will post the code in a minute), the next part takes the user name from the initialize data and the user group from the .Net form and it is supposed to add the user to the group using the "add user to group" activity of SCCM. – Herculeon May 12 '17 at 19:32
  • this is the code for the form: – Herculeon May 12 '17 at 19:33
  • Please [edit] your code properly into the question itself. Consider reading [ask] and how to create a [mcve]. – gravity May 12 '17 at 19:33
  • this is the code for the form: [array]$DropDownArrayItems = "","OLD_DATABASES","Management","Auditor","Administration","Building","Code_Enforcement","Inspections","Licensing","Block_Database","Zoning","Administration","City_Clerk","Clerk","Mail","Records","CMO","CMO_Administration","CMO_LTPS","CP_Administration","Community_Programs","ENG_Administration","Airport","AlphaCard","Drafting","Engineering","Engineering_Division","GIS","Inspection","Landscape","Real_Estate", – Herculeon May 12 '17 at 19:49
  • "Site_Plan_Review","Stormwater","Survey","Traffic","Utilities","DBAdministration","EU_CSO","EU_Electric_Utility","EU_Energy_Management","EU_Engineering","EU_GIS","EU_Meter","SEL_Device_Manager","Substation","System_Control","Telecom","Transmission_and_Distribution","Accounting","FIN_Administration","FIN_Budget","FIN_Finance","FIN_Program_Evaluation","Treasury","DB_Fire","Fire_Administration","Fire_Dispatch","Fire_Stations","FL_Administration","FL_Fleet","Golf_Equipment_Maintenance","Heavy_Truck","Light_Equipment","Small_Equipment","Stores"," – Herculeon May 12 '17 at 19:50
  • HR_Administration","HR_Clinic","HR_Human_Resources","HR_Safety","HR_Training","Admin_Access","Help_Desk","Information_Technology","PL_Administration","Community_Development","Planning","PL_Administration","PUR_Purchasing","PUR_Warehouse","PW_Administration","PW_Commercial_Sanitation","Facilities_Maintenance","PW_Public_Works","Residential_Sanitation","PW_Stormwater","PW_Streets","RM_Administr – Herculeon May 12 '17 at 19:50
  • ation","Employee_Insurances","M_Employer_Insurances","Risk_Management","RP_Administration","RP_Enforcement","RP_Events","RP_Golf","RP_Parks","RP_Recreation","RP_Recreation_and_Parks","RP_Special_Services","Trailer_Park","ST_Administration","Suntran","TPO","TPO_Administration","WS_Administration","WS_Central_Lines","WS_Central_Maintenance","WS_Compliance_Monitoring","WS_Water_and_Sewer","WS_Water_Treatment_Plant","WS_WRF1","WS_WRF2","WS_WRF3","CAL – Herculeon May 12 '17 at 19:50
  • M" [array]$DropDownArray = $DropDownArrayItems | sort # This Function Returns the Selected Value and Closes the Form function Return-DropDown { if ($DropDown.SelectedItem -eq $null){ $DropDown.SelectedItem = $DropDown.Items[0] $script:Choice = $DropDown.SelectedItem.ToString() $Form.Close() } else{ $script:Choice = $DropDown.SelectedItem.ToString() $Form.Close() } } function SelectGroup{ [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") – Herculeon May 12 '17 at 19:52
  • [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $Form = New-Object System.Windows.Forms.Form $Form.width = 400 $Form.height = 150 $Form.Text = ”DropDown” – Herculeon May 12 '17 at 19:52
  • $DropDown = new-object System.Windows.Forms.ComboBox $DropDown.Location = new-object System.Drawing.Size(100,10) $DropDown.Size = new-object System.Drawing.Size(250,30) ForEach ($Item in $DropDownArray) { [void] $DropDown.Items.Add($Item) } $Form.Controls.Add($DropDown) $DropDownLabel = new-object System.Windows.Forms.Label $DropDownLabel.Location = new-object System.Drawing.Size(10,10) $DropDownLabel.size = new-object System.Drawing.Size(100,40) $DropDownLabel.Text = "Select Group:" $Form.Controls.Add($DropDownLabel) – Herculeon May 12 '17 at 19:52
  • $Button = new-object System.Windows.Forms.Button $Button.Location = new-object System.Drawing.Size(100,50) $Button.Size = new-object System.Drawing.Size(100,20) $Button.Text = "Select an Item" $Button.Add_Click({Return-DropDown}) $form.Controls.Add($Button) $form.ControlBox = $false $Form.Add_Shown({$Form.Activate()}) [void] $Form.ShowDialog() return $script:choice } $Group = $null $Group = SelectGroup while ($Group -like ""){ $Group = SelectGroup } – Herculeon May 12 '17 at 19:52
  • 1
    Wow that does not look good. Is there a way to post the code without doing this? It is almost unreadable. – Herculeon May 12 '17 at 19:55
  • 4
    How about editing the question and using a code-block? – Frode F. May 12 '17 at 20:05
  • Ok, I am not sure about how to do that. If anyone can just bypass this and give me the code for a form that will pull groups from AD and add the inputted user into the selected group, I will make that work with SCCM. I just do not know the proper code to do that. – Herculeon May 12 '17 at 20:22
  • updated your question with the code you provided, also corrected the scope (you were calling `$DropDownArray` outside the `SelectGroups` functions scope, so I set the variable at the script scope) – scrthq May 13 '17 at 00:11

0 Answers0