Powershell script Get AD Group report - powershell
I am working on a script and am stuck at an error I am getting. I wanted to see if anyone could point me in the right direction. Basically I want a user to search AD and generate a report in.CSV file of the users in a particular group. I will show the script and the error below. Any advice would be most welcome. I know it can be done better and cleaned up but for now, it works.
<#
.NOTES
===========================================================================
Created with: PowerShell
Created on: 6/8/2020 3:51 PM
Created by: William Christner
Organization: BCBSA
Filename: AD Group Report
===========================================================================
.DESCRIPTION
Search AD groups, create a .CSV report of users in the group.
#>
####################################################################
import-module ActiveDirectory
####################################################################
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Select AD Group'
$form.Size = New-Object System.Drawing.Size(350, 140)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(125, 50)
$okButton.Size = New-Object System.Drawing.Size(75, 23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$okButton.add_Click({
######################################################################################################
$GroupName = "$textBox"
$Date = Get-Date -UFormat "%m.%d.%y_%H.%M"
$Members = Get-ADGroupMember -Identity $GroupName -Recursive | Select -ExpandProperty SAMAccountName
Foreach ($Name in $Members) {
Get-ADUser $Name -properties * | Select EmailAddress,SAMAccountName,DisplayName,OfficePhone,CanonicalName,Enabled |
Export-Csv -append C:\Reports\$($GroupName)_Membership_Detailed_$($Date).csv -NoTypeInformation -Encoding UTF8 }
})
#####################################################################################################################
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(225, 50)
$cancelButton.Size = New-Object System.Drawing.Size(75, 23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.Size = New-Object System.Drawing.Size(130, 20)
$label.Text = 'Please select AD Group:'
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(150, 15)
$textBox.Size = New-Object System.Drawing.Size(150, 40)
$form.Controls.Add($textBox)
$textbox.AutoCompleteSource = 'CustomSource'
$textbox.AutoCompleteMode = 'SuggestAppend'
$textbox.AutoCompleteCustomSource = $autocomplete
"awsarchitect",
"BHI",
"cc_support",
"Citrix",
"CyberArk",
"CyberArk_Admins",
"Datastage",
"DB2DBA",
"Distribution Groups",
"DS_Core_Security",
"DS_FEPSIU",
"ems-test",
"FAS_COLDFUSION_DEV",
"FEPBlue",
"FEPOC_MousePointer",
"FogOperations",
"GG_AcceletestAdmins",
"GG_AcceletestUsers",
"GG_Allow LinkedIn",
"GG_Allow_AWS",
"GG_Allow_Firewall_ERwin",
"GG_Allow_Firewall_Hyper-V",
"GG_Allow_Firewall_IBM_Websphere",
"GG_Allow_Firewall_Loadrunner",
"GG_Allow_Firewall_Mainframe",
"GG_Allow_Firewall_NEBA_FTP",
"GG_Allow_Firewall_nodejs",
"GG_Allow_Firewall_Observer_Platform",
"GG_Allow_Firewall_R_Selenium",
"GG_Allow_Firewall_Safeend_DPA",
"GG_Allow_Firewall_SoapUI",
"GG_Allow_Lockdown",
"GG_Allow_MS_Collab_Sites",
"GG_Allow_Skype",
"GG_Allow_Website_Menshealth",
"GG_Allow_Windows_GINA",
"GG_Allow_Wireless",
"GG_Ansible_Development",
"GG_ApplicationSupport_Users",
"gg_bcbsa_sp_audit",
"GG_BindAccounts",
"GG_Blackberry_SSP",
"GG_Chrome_NoPolicies",
"GG_Clearwell_Admin",
"GG_Container_Admins_Nonprod",
"GG_ContentDistributor",
"GG_Contingent",
"GG_Core_GPO",
"GG_Core_GPO_POC",
"GG_Core_Mid",
"GG_CredSSP_Vuln",
"GG_CTX_Allow_Shadow",
"GG_DEP_Disabled",
"GG_DevFep",
"GG_DriveMappings_Test_Group",
"GG_Dropbox ",
"GG_DUOAlerts",
"GG_eDiscovery_Collections",
"GG_EMS_Files",
"GG_EV_Client11_Pilot",
"GG_EV_Phase2_Pilot",
"GG_Exchange_CalendarAdmins",
"GG_Exchange_ISAdmin",
"GG_Exchange_JrAdmin",
"GG_Exchange_MidAdmin",
"GG_Exchange_PowerShell",
"GG_Exchange_SrAdmin",
"GG_Exchange_Training",
"GG_Extend_ScreenSaver",
"gg_fep_contingents",
"GG_FEP_PS_Admins",
"GG_FEP_SIU",
"GG_FEP_SIU_Legal",
"gg_fep_sr_staff",
"gg_fep_staff",
"GG_Firewall_Testing",
"GG_Firewall_Triage",
"GG_Foglight_Read",
"GG_Git-Admins",
"GG_Git-Users",
"GG_Google_Man",
"GG_Google_SU",
"GG_GPO-Arch",
"GG_IBC_SandBox",
"GG_IDN_Pilot",
"GG_Infosys",
"GG_iSight-SRM",
"GG_JumpServers",
"GG_L4CERT_Administrators",
"GG_Legal_Hold",
"GG_Legal_Hold_Pilot",
"GG_LocalProfileRedirect_CHG",
"GG_LocalProfileRedirect_MDC",
"GG_Lost_Devices",
"GG_LTDMailbox",
"GG_Microsoft_Patch_Alerts",
"GG_Mobile_Users_CHG",
"GG_Mobile_Users_Execs",
"GG_Mobile_Users_MDC",
"GG_MSP_Infosys",
"GG_MSP_TechMahindra",
"GG_MSP_UST",
"GG_No_WPAD",
"GG_NRS_Extracts_Access",
"GG_O365_Migration",
"GG_OneDrive_Pilot",
"GG_PeopleSoft_Testers",
"GG_Proxy_WPAD2",
"GG_RDM_ADMIN_NP",
"GG_RDM_Admin_p",
"GG_RDM_ALL",
"GG_RDM_APP_NP",
"GG_RDM_BDC",
"GG_RDM_BLUE2",
"GG_RDM_IPDS",
"GG_RDM_ITS",
"GG_RDM_LDLA",
"GG_RDM_PDSU",
"GG_RDM_TREATMENT_CATEGORY",
"GG_RDM_USER_NP",
"GG_RDM_User_p",
"GG_RDM_WEB_SERVICES",
"GG_RDP_Users ",
"GG_RecordPoint365_Admins",
"GG_Remove_ScreenSaver",
"GG_RMS_SuperUsers",
"GG_Screensaver_Blank",
"GG_Screensaver_Presentations",
"GG_Screensaver_Windows10_Lockscreen",
"GG_SIEM_Log_Captures",
"GG_SIEM_Log_Captures_CHG",
"GG_SIEM_Log_Captures_MDC",
"GG_SIEM_Log_Captures_NGS",
"GG_SIEM_Log_Captures_Rollback",
"GG_StaffNow",
"GG_StateAffairs",
"GG_Tableau_Admin ",
"GG_UC_VMware_Admin",
"GG_VDI_Application_Permissions",
"GG_VDI_PEOPLESOFT_REPORTING-FEPprd",
"GG_VDIDesktopSupport",
"GG_Web_Servers",
"GG_WebEx_Users",
"GG_Windows10_GPO_Testing",
"GG_Windows10_Users",
"GG_Wireless_Profile_Testers",
"GG_Wireless_Testers",
"HPE_IRS",
"Hyperion-Users",
"HyperV_Servers",
"Informatica",
"JohnsAwesomeGPOTestingGroup",
"mongo_nw_pe",
"mongo_rw_dev",
"mongo_rw_pv",
"NetApp",
"NoOutlookNoIE",
"NOW_Upgrade_Temp12",
"O365",
"OKTA",
"Projects",
"QualityStage",
"sco",
"SCOM",
"SCVMM",
"SNOW_Upgrade_Temp_test",
"SNOW_Upgrade_Temp11",
"SNOW_Upgrade_Temp12",
"SNOW_Upgrade_Temp123",
"SNOW_Upgrade_Temp1256",
"SNOW_Upgrade_Temp132",
"SNOW_Upgrade_Temp145",
"SNOW_Upgrade_Temp2",
"SNOW_Upgrade_Temp3",
"SNOW_Upgrade_Temp33",
"SNOW_Upgrade_Temp444",
"SNOW_Upgrade_Temp555",
"SNOW_Upgrade_Temp888",
"Specopshe",
"SUG_FlashPlayerPilot",
"SystemCenter",
"Tower",
"UCSD",
"VCO-Admin",
"VMware"| % { $textbox.AutoCompleteCustomSource.AddRange($_) }
#[void]$listBox.Items.Add('atl-dc-001')
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $listBox.SelectedItem
$x
}
The error I am getting is as follows:
Looks like it is not seeing the Group in the Domain however when I run the same script it dose work by itself and created the report. I am thinking there is something missing from the textbox input and the rest of the script.
Thanks again for taking a look.
Cheers
You'll want to grab the textbox value from it's Text property:
$GroupName = $textBox.Text
Related
Use script variable inside textbox form
I’m trying to create a form which contains a message where I want to use some data imported from a CSV file. The script will read the CSV rows and print a message that will contain data from it. The issue is that the variables inside message textbox is not used instead a plain text is filled. I think that this is related to System.Windows.Forms.TextBox but I can't figure it out Any idea how I can resolve this? Regards, Adrian Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName PresentationFramework function show_menu { [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $form = New-Object System.Windows.Forms.Form $form.Text = 'menu' $form.Size = New-Object System.Drawing.Size(630,370) $form.StartPosition = 'CenterScreen' $form.FormBorderStyle = 'FixedSingle' #$form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon()) $okButton = New-Object System.Windows.Forms.Button $okButton.Location = New-Object System.Drawing.Point(200,295) $okButton.Size = New-Object System.Drawing.Size(75,23) $okButton.Text = 'OK' $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $okButton.Add_Click({ $form.Tag = $textBox_recipient.Text; $form.Tag = $textBox_message.Text; $form.Close() }) $form.AcceptButton = $okButton $form.Controls.Add($okButton) $cancelButton = New-Object System.Windows.Forms.Button $cancelButton.Location = New-Object System.Drawing.Point(355,295) $cancelButton.Size = New-Object System.Drawing.Size(75,23) $cancelButton.Text = 'Cancel' $cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.CancelButton = $cancelButton $form.Controls.Add($cancelButton) $textBox_recipient = New-Object System.Windows.Forms.TextBox $textBox_recipient.Location = New-Object System.Drawing.Point(210,70) $textBox_recipient.Size = New-Object System.Drawing.Size(245, 20) $textBox_recipient.ReadOnly = $true $form.Controls.Add($textBox_recipient) ## $textBox_recipient_select = New-Object System.Windows.Forms.Button $textBox_recipient_select.Location = New-Object System.Drawing.Point(460, 70) $textBox_recipient_select.Size = New-Object System.Drawing.Size(100, 20) $textBox_recipient_select.Text = "Select CSV file" $textBox_recipient_select.add_Click({ $ofd = New-Object system.windows.forms.Openfiledialog #$ofd.Filter = 'Supported file types (*.csv,*.xlsx)|*.csv,*.xlsx' $ofd.Filter = 'Supported file types (*.csv, *.xlsx)|*.csv; *.xlsx| All (*.*)|*.*' $script:recipient_filename = 'Not found' if ($ofd.ShowDialog() -eq 'Ok') { $script:recipient_filename = $textbox_recipient.Text = $ofd.FileName } }) #$textBox_recipient.Text = "C:\Users\Ady\Desktop\test.csv" $form.Controls.Add($textBox_recipient_select) $label_message = New-Object System.Windows.Forms.Label $label_message.Location = New-Object System.Drawing.Point(10,150) $label_message.Size = New-Object System.Drawing.Size(200,20) $label_message.BackColor = [System.Drawing.Color]::FromName("Transparent") $label_message.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 10, [System.Drawing.FontStyle]::Bold) $label_message.Text = 'Message:' $form.Controls.Add($label_message) $textBox_message = New-Object System.Windows.Forms.TextBox $textBox_message.Multiline = $True $textBox_message.Scrollbars = "Vertical" $textBox_message.Location = New-Object System.Drawing.Point(210,150) $textBox_message.Size = New-Object System.Drawing.Size(350, 135) $textBox_message.Text = "Insert your text here. HTML format supported" $form.Controls.Add($textBox_message) $form.Topmost = $true $form.Add_Shown({ $textBox_recipient.Select(),$textBox_message.Select() }) $result = $form.ShowDialog() if ($result -eq [System.Windows.Forms.DialogResult]::OK) { $script:filename = "$(($textBox_recipient).Text)" $recipients = Import-csv -Path "$filename" $total_recipient_nr = get-content "$filename" | select-string "#" | measure-object -line $recipient_nr = 0 foreach ($recipient in $recipients) { if (++$recipient_nr % 31 -eq 0) { Start-Sleep -Seconds 30 echo "waiting 1 minute" } $script:user_email = $recipient.email $script:user_firstname = $recipient.firstname $script:user_lastname = $recipient.lastname $script:user_code = $recipient.code $script:message = $textBox_message.Text Write-Host $message } } } show_menu For example, the following csv: firstname, lastname, email, code ---- header of csv file firstname1, lastname1, email1#domain, code1 firstname2, lastname2, email2#domain, code2 What I want to do is to use variables like $user_email, $user_code inside "$textBox_message.Text" field of the form and for each line of the CSV file, the message to use the value of those variables. (recipient is a row from the csv file that contains different values at each foreach run) $script:user_firstname = $recipient.firstname $script:user_code = $recipient.code $script:message = $textBox_message.Text I run the script, the form appears and I replace the default text "Insert your text here. HTML format supported" of $textBox_message.Text with the following: Hi $user_firstname. This is your code: $user_code The result (value of $message var) by executing line 96, should be: Hi firstname1. This is your code: code1 - at first run of foreach loop and Hi firstname2. This is your code: code2 - at second run of foreach loop Instead, the result is: Hi $user_firstname. This is your code: $user_code --- plain text (the value) of $message
This is from what I have observed from Powershell when trying to writing a simple string with variables: if you use single quotes i.e. $firstName = "John" write-host 'First name is $firstName' The output is going to be: First name is $firstName However if you use double quotes, you should get the variable value instead of variable being displayed as plain text. i.e. $firstName = "John" write-host "First name is $firstName" or write-host "First name is $($firstName)" you should get the desired output: First name is John
Powershell Script to get software Version of Adobe Connect & Zoom with GUI Error
Working on Powershell script to get adobe connect and Zoom Version in GUI. and getting hyperlink displayed. Any help will be highly appreciated. Issue 1 - Both software version is not visible. Only one getting displayed either zoom or Adobe in output Issue 2 - Unable to get Hyperlink for both row. Getting only for one at a time. $ErrorActionPreference = "SilentlyContinue" Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $font = New-Object System.Drawing.Font("Arial", 9) $form = New-Object System.Windows.Forms.Form $form.Text = 'PLT Readiness' $form.Size = New-Object System.Drawing.Size(325,225) $form.StartPosition = 'CenterScreen' $form.Icon = 'C:\Users\C899414\Desktop.ico' $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Point(120,150) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = 'OK' $OKButton.TextAlign = 'MiddleCenter' $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.AcceptButton = $OKButton $form.Controls.Add($OKButton) $LinkLabel = New-Object System.Windows.Forms.LinkLabel $LinkLabel.Location = New-Object System.Drawing.Point(81,110) $LinkLabel.Size = New-Object System.Drawing.Size(280,20) $LinkLabel.Font = $font $LinkLabel.LinkColor = "BLUE" $LinkLabel.ActiveLinkColor = "RED" $LinkLabel.Text = "Ticketsystem" $LinkLabel.add_Click({[system.Diagnostics.Process]::start("https://service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3D-1%26sysparm_query%3Dactive%3Dtrue%26sysparm_stack%3Dincident_list.do%3Fsysparm_query%3Dactive%3Dtrue")}) $Form.Controls.Add($LinkLabel) $software = New-Object System.Windows.Forms.Label $software.Location = New-Object System.Drawing.Point(10,50) $software.Size = New-Object System.Drawing.Size(280,20) $software.Font = $font $software.Text = "Adobe Connect: $((Get-WMIObject Win32_Product | Where-Object {$_.Name -like 'Adobe Connect Application*'} | Select-Object Version))" $software.Text = "Zoom: $((Get-WMIObject Win32_Product | Where-Object {$_.Name -like 'Zoom*'} | Select-Object Version))" $form.Controls.Add($software) $help = New-Object System.Windows.Forms.Label $help.Location = New-Object System.Drawing.Point(10,110) $help.Font = $font $help.Size = New-Object System.Drawing.Size(280,20) $help.Text = "Help:" $form.Controls.Add($help) $help2 = New-Object System.Windows.Forms.Label $help2.Location = New-Object System.Drawing.Point(10,130) $help2.Font = $font $help2.Size = New-Object System.Drawing.Size(280,20) $help2.Text = "Update From Software Center:" $form.Controls.Add($help) $form.Topmst = $true $form.ShowDialog()
Removing dynamic text from a temp file in a script
Ok, I know this is going to end up being basic but I cant seem to figure it out. I am trying to build a tool that will allow us to get the full AD group name for a user. The current problem we have is that the names of our AD groups are long, so a net user MrSmith /domain ends up truncating the full AD group name. I tried using a gpresult -user MrSmith /r but this doesnt return all of the AD groups for some reason. So I decided that I would create something new that will also have other applications later on. I want to do this by first: doing a net group /domain to pull all of the AD groups in the DC. Second run a net group $ADGroup /domain for each of the ADGroups in the domain and use that output to search for the specified user ID and create a new output that displays the full name of each AD group that user ID is a part of. I am putting this in a drop down GUI for some of the future features I want to add. Now I have got a good chunk of the first step done, but obviously I am running into an issue. When I do the net group /domain i get output looking like The request will be processed at a domain controller for domain MyComapny.com. Group Accounts for \\Server.MyComapny.com ------------------------------------------------------------------------------- *AD_Group_1 *AD_Group_2 *AD_Group_3 *AD_Group_4 ..... And I add this to a temp .txt file for use. The Issue I am having is that its not performing the net group $Choice /domain on the AD group selected from the drop down and I dont know why. Any advice is welcome, I know I am not the best at this so my format and style may not be standard. Clear-Variable DropDownList $RawADGroups = Net Group /domain >> 'C:\script_out\RawADList1.txt' (get-content -path 'C:\script_out\RawADList1.txt') | ForEach-Object {$_ -replace '\*',''} >> 'C:\script_out\RawADList2.txt' [string[]]$DropDownList = Get-Content -Path 'C:\script_out\RawADList2.txt' Remove-Item 'C:\script_out\RawADList1.txt' Remove-Item 'C:\script_out\RawADList2.txt' function Return-DropDown { $Choice = $DropDown.SelectedItem.ToString() if ($Choice) {net group $Choice /domain } } [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $Form = New-Object System.Windows.Forms.Form $Form.width = 340 $Form.height = 150 $Form.Text = "ADGroup" $DropDown = new-object System.Windows.Forms.ComboBox $DropDown.Location = new-object System.Drawing.Size(10,10) $DropDown.Size = new-object System.Drawing.Size(300,30) ForEach ($Line in $DropDownList) { $DropDown.Items.Add($Line) } $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(200,20) $Form.Controls.Add($DropDownLabel) $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 = "Pick One" $Button.Add_Click({Return-DropDown}) $form.Controls.Add($Button) $Form.Add_Shown({$Form.Activate()}) $Form.ShowDialog() When I click the Pick One button nothing happens, it doesnt reflect anything.
I Figured this out, it was as I thought VERY simple, I was just forgetting to have the command do anything with the output. Hope this might help someone else. Clear-Variable DropDownList $RawADGroups = Net Group /domain >> 'C:\script_out\RawADList1.txt' (get-content -path 'C:\script_out\RawADList1.txt') | ForEach-Object {$_ -replace '\*',''} >> 'C:\script_out\RawADList2.txt' [string[]]$DropDownList = Get-Content -Path 'C:\script_out\RawADList2.txt' Remove-Item 'C:\script_out\RawADList1.txt' Remove-Item 'C:\script_out\RawADList2.txt' function Return-DropDown { $Choice = $DropDown.SelectedItem.ToString() if ($Choice) { net group $Choice /domain >> C:\script_out\output.txt } } [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $Form = New-Object System.Windows.Forms.Form $Form.width = 340 $Form.height = 150 $Form.Text = "ADGroup" $DropDown = new-object System.Windows.Forms.ComboBox $DropDown.Location = new-object System.Drawing.Size(10,10) $DropDown.Size = new-object System.Drawing.Size(300,30) ForEach ($Line in $DropDownList) { $DropDown.Items.Add($Line) } $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(200,20) $Form.Controls.Add($DropDownLabel) $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 = "Pick One" $Button.Add_Click({Return-DropDown}) $form.Controls.Add($Button) $Form.Add_Shown({$Form.Activate()}) $Form.ShowDialog()
How to have multiple input fields in the same input box
I would like to have a tech enter in the username and the group name but in one input box. Anyone willing to tell me how to do this? Function add-togroup{ #Adds members to group in AD #$users = Read-Host "Enter a username" Add-Type -AssemblyName Microsoft.VisualBasic; $value = [Microsoft.VisualBasic.Interaction]::InputBox('Enter username', 'Username') $value2 = [Microsoft.VisualBasic.Interaction]::InputBox('Enter group name', 'XA Group','') $group_membership = Get-ADPrincipalGroupMembership $users | select name | format-table -auto foreach($u in $value) { Add-ADGroupMember $value2 -Members $u } Write-Host $group_membership } So I am capable of using multiple dialogs in sequence but it would make for a better user experience if I could roll this into one single box /form.
If you are not satisfied with the basic forms available then one option you have is to roll your own in PowerShell with .Net forms. Just to show an example that you can build from... [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Data Entry Form" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({ if ($_.KeyCode -eq "Enter" -or $_.KeyCode -eq "Escape"){ $objForm.Close() } }) $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($OKButton) $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(150,120) $CancelButton.Size = New-Object System.Drawing.Size(75,23) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(10,20) $objLabel.Size = New-Object System.Drawing.Size(280,20) $objLabel.Text = "Please enter the information in the space below:" $objForm.Controls.Add($objLabel) $objTextBox = New-Object System.Windows.Forms.TextBox $objTextBox.Location = New-Object System.Drawing.Size(10,40) $objTextBox.Size = New-Object System.Drawing.Size(260,20) $objForm.Controls.Add($objTextBox) $objTextBox2 = New-Object System.Windows.Forms.TextBox $objTextBox2.Location = New-Object System.Drawing.Size(10,70) $objTextBox2.Size = New-Object System.Drawing.Size(260,20) $objForm.Controls.Add($objTextBox2) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void]$objForm.ShowDialog() $objTextBox.Text $objTextBox2.Text The borrows heavily from the great primer on the subject on TechNet which you should read as it walks you though this better. I removed some of the variable population logic as it was flawed and added another text box. The last two lines return the values entered by the "user". Aside from the addition of the text box I have left most other cosmetic changes up to you to help you get a better understanding of what is involved here. Keep in mind the locations and sizes of newly added objects and be sure you actually add it to the form. Since there is not GUI for form building it can seem daunting but its not really that hard to do. You just need to experiment. If you are so inclined there are 3rd party tools that will help with that.
Below is the code where I am trying to get the operating system name for multiple system
If I give one system, it is working. If I give multiple systems it is showing RPC error. If I give my system twice, then it also is not working. Any idea? Function Get_Systeminfo() { $TxtBox.Visible = $false $ColName = #{Expression={$_.CSNAME};Label="SERVER NAME"}, #{Expression={$_.Caption};Label="OS NAME"; width =25}, #{Expression={$_.OSArchitecture};Label="OS TYPE"} $ResBox = New-Object System.Windows.Forms.RichTextBox $ResBox.Location = New-Object System.Drawing.Size(50,50) $ResBox.Size = New-Object System.Drawing.Size(480, 280) $ResBox.Font = "lucida console" $objForm.Controls.Add($ResBox) $ResBox.Text = foreach ($list in $TxtBox.Text) { Get-WmiObject Win32_OperatingSystem -ComputerName $list | Format-Table $ColName -Auto | Out-String } } $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "SystemInfo" $objForm.Size = New-Object System.Drawing.Size(600,400) $objForm.StartPosition = "CenterScreen" $TxtBox = New-Object System.Windows.Forms.TextBox $TxtBox.Location = New-Object System.Drawing.Size(20, 20) $TxtBox.Size = New-Object System.Drawing.Size(300,100) $TxtBox.Multiline = $true $objForm.Controls.Add($TxtBox) $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(20,340) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $objForm.Controls.Add($OKButton) $OKButton.Add_Click({Get_Systeminfo}) $objForm.ShowDialog()
Change $ResBox.Text = foreach ($list in $TxtBox.Text){ to $ResBox.Text = foreach ($list in $TxtBox.Lines){ and it will genereate output, IF you are giving a single name per line.