@@ -73,45 +73,45 @@ $comboDomain = New-Object Windows.Forms.ComboBox -Property @{ Location = '10,30'
7373$comboDomain.Items.AddRange ((Get-ADForest ).Domains)
7474$comboDomain.SelectedIndex = 0
7575$form.Controls.AddRange (@ (
76- (New-Object Windows.Forms.Label - Property @ { Text = " Select Domain:" ; Location = ' 10,10' ; Size = ' 200,20' }),
77- $comboDomain
78- ))
76+ (New-Object Windows.Forms.Label - Property @ { Text = " Select Domain:" ; Location = ' 10,10' ; Size = ' 200,20' }),
77+ $comboDomain
78+ ))
7979
8080$txtSearch = New-Object Windows.Forms.TextBox - Property @ { Location = ' 10,80' ; Size = ' 660,25' }
8181$btnClearSearch = New-Object Windows.Forms.Button - Property @ { Text = " Clear Search" ; Location = ' 580,110' ; Size = ' 90,25' }
8282$form.Controls.AddRange (@ (
83- (New-Object Windows.Forms.Label - Property @ { Text = " Search Groups:" ; Location = ' 10,60' ; Size = ' 200,20' }),
84- $txtSearch , $btnClearSearch
85- ))
83+ (New-Object Windows.Forms.Label - Property @ { Text = " Search Groups:" ; Location = ' 10,60' ; Size = ' 200,20' }),
84+ $txtSearch , $btnClearSearch
85+ ))
8686
8787$listGroups = New-Object Windows.Forms.ListView - Property @ { Location = ' 10,140' ; Size = ' 660,200' ; View = ' Details' ; CheckBoxes = $true }
8888[void ]$listGroups.Columns.Add (" Group Name" , 640 )
8989$chkSelectAll = New-Object Windows.Forms.CheckBox - Property @ { Text = " Select All" ; Location = ' 10,120' ; Size = ' 100,20' }
9090$form.Controls.AddRange (@ ($chkSelectAll , $listGroups ))
9191
9292$listAttr = New-Object Windows.Forms.CheckedListBox - Property @ { Location = ' 10,360' ; Size = ' 660,100' }
93- $listAttr.Items.AddRange (@ (' Name' , ' SamAccountName' , ' UserPrincipalName' , ' EmailAddress' , ' DisplayName' , ' Title' , ' Department' , ' Company' , ' Manager' , ' Enabled' , ' AccountLockoutTime' , ' LastLogonDate' , ' WhenCreated' ))
93+ $listAttr.Items.AddRange (@ (' Name' , ' SamAccountName' , ' UserPrincipalName' , ' EmailAddress' , ' DisplayName' , ' Title' , ' Department' , ' Company' , ' Manager' , ' Enabled' , ' AccountLockoutTime' , ' LastLogonDate' , ' WhenCreated' ))
9494$form.Controls.AddRange (@ (
95- (New-Object Windows.Forms.Label - Property @ { Text = " Select Attributes:" ; Location = ' 10,340' ; Size = ' 200,20' }),
96- $listAttr
97- ))
95+ (New-Object Windows.Forms.Label - Property @ { Text = " Select Attributes:" ; Location = ' 10,340' ; Size = ' 200,20' }),
96+ $listAttr
97+ ))
9898
9999$txtOut = New-Object Windows.Forms.TextBox - Property @ { Location = ' 10,480' ; Size = ' 560,25' ; Text = [Environment ]::GetFolderPath(" MyDocuments" ) }
100100$btnBrowse = New-Object Windows.Forms.Button - Property @ { Text = " Browse" ; Location = ' 580,480' ; Size = ' 90,25' }
101101$btnBrowse.Add_Click ({
102- $fbd = New-Object Windows.Forms.FolderBrowserDialog
103- if ($fbd.ShowDialog () -eq " OK" ) { $txtOut.Text = $fbd.SelectedPath }
104- })
102+ $fbd = New-Object Windows.Forms.FolderBrowserDialog
103+ if ($fbd.ShowDialog () -eq " OK" ) { $txtOut.Text = $fbd.SelectedPath }
104+ })
105105$form.Controls.AddRange (@ (
106- (New-Object Windows.Forms.Label - Property @ { Text = " Output Folder:" ; Location = ' 10,460' ; Size = ' 200,20' }),
107- $txtOut , $btnBrowse
108- ))
106+ (New-Object Windows.Forms.Label - Property @ { Text = " Output Folder:" ; Location = ' 10,460' ; Size = ' 200,20' }),
107+ $txtOut , $btnBrowse
108+ ))
109109
110110$logBox = New-Object Windows.Forms.RichTextBox - Property @ { Location = ' 10,520' ; Size = ' 660,80' ; ReadOnly = $true ; ScrollBars = ' Vertical' }
111111$form.Controls.AddRange (@ (
112- (New-Object Windows.Forms.Label - Property @ { Text = " Log:" ; Location = ' 10,500' ; Size = ' 200,20' }),
113- $logBox
114- ))
112+ (New-Object Windows.Forms.Label - Property @ { Text = " Log:" ; Location = ' 10,500' ; Size = ' 200,20' }),
113+ $logBox
114+ ))
115115
116116$progress = New-Object Windows.Forms.ProgressBar - Property @ { Location = ' 10,610' ; Size = ' 660,15' }
117117$lblStatus = New-Object Windows.Forms.Label - Property @ { Text = " Ready" ; Location = ' 10,630' ; Size = ' 660,20' }
@@ -147,96 +147,96 @@ $comboDomain.Add_SelectedIndexChanged({ Load-Groups })
147147$searchTimer = New-Object System.Windows.Forms.Timer
148148$searchTimer.Interval = 300
149149$searchTimer.Add_Tick ({
150- $searchTimer.Stop ()
151- if ($null -eq $allGroups -or $allGroups.Count -eq 0 ) { return }
152- $searchText = $txtSearch.Text.ToLowerInvariant ().Trim()
153- $listGroups.BeginUpdate ()
154- $listGroups.Items.Clear ()
155- foreach ($g in $allGroups ) {
156- if ($g.Name -and $g.Name.ToLowerInvariant ().Contains($searchText )) {
157- $item = New-Object Windows.Forms.ListViewItem $g.Name
158- if ($checkedGroups.Contains ($g.Name )) { $item.Checked = $true }
159- $listGroups.Items.Add ($item )
150+ $searchTimer.Stop ()
151+ if ($null -eq $allGroups -or $allGroups.Count -eq 0 ) { return }
152+ $searchText = $txtSearch.Text.ToLowerInvariant ().Trim()
153+ $listGroups.BeginUpdate ()
154+ $listGroups.Items.Clear ()
155+ foreach ($g in $allGroups ) {
156+ if ($g.Name -and $g.Name.ToLowerInvariant ().Contains($searchText )) {
157+ $item = New-Object Windows.Forms.ListViewItem $g.Name
158+ if ($checkedGroups.Contains ($g.Name )) { $item.Checked = $true }
159+ $listGroups.Items.Add ($item )
160+ }
160161 }
161- }
162- $listGroups.EndUpdate ()
163- })
162+ $listGroups.EndUpdate ()
163+ })
164164
165165$txtSearch.Add_TextChanged ({
166- $searchTimer.Stop ()
167- $searchTimer.Start ()
168- })
166+ $searchTimer.Stop ()
167+ $searchTimer.Start ()
168+ })
169169
170170$listGroups.Add_ItemChecked ({
171- param ($s , $e )
172- try {
173- if ($e -and $e.Item -and $e.Item.Text ) {
174- if ($e.Item.Checked ) {
175- $checkedGroups.Add ($e.Item.Text ) | Out-Null
176- } else {
177- $checkedGroups.Remove ($e.Item.Text ) | Out-Null
171+ param ($s , $e )
172+ try {
173+ if ($e -and $e.Item -and $e.Item.Text ) {
174+ if ($e.Item.Checked ) {
175+ $checkedGroups.Add ($e.Item.Text ) | Out-Null
176+ } else {
177+ $checkedGroups.Remove ($e.Item.Text ) | Out-Null
178+ }
178179 }
180+ } catch {
181+ Write-Log " Error on item check event: $_ " " WARNING"
179182 }
180- } catch {
181- Write-Log " Error on item check event: $_ " " WARNING"
182- }
183- })
183+ })
184184
185185$chkSelectAll.Add_CheckedChanged ({
186- $listGroups.BeginUpdate ()
187- foreach ($item in $listGroups.Items ) {
188- $item.Checked = $chkSelectAll.Checked
189- if ($chkSelectAll.Checked ) {
190- $checkedGroups.Add ($item.Text ) | Out-Null
191- } else {
192- $checkedGroups.Remove ($item.Text ) | Out-Null
186+ $listGroups.BeginUpdate ()
187+ foreach ($item in $listGroups.Items ) {
188+ $item.Checked = $chkSelectAll.Checked
189+ if ($chkSelectAll.Checked ) {
190+ $checkedGroups.Add ($item.Text ) | Out-Null
191+ } else {
192+ $checkedGroups.Remove ($item.Text ) | Out-Null
193+ }
193194 }
194- }
195- $listGroups.EndUpdate ()
196- })
195+ $listGroups.EndUpdate ()
196+ })
197197
198198$btnClearSearch.Add_Click ({ $txtSearch.Text = " " })
199199
200200$btnExport.Add_Click ({
201- $domain = $comboDomain.SelectedItem
202- $attrs = $listAttr.CheckedItems
203- $output = $txtOut.Text
204- $csvPath = Join-Path $output " $domain `_Export_$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) .csv"
201+ $domain = $comboDomain.SelectedItem
202+ $attrs = $listAttr.CheckedItems
203+ $output = $txtOut.Text
204+ $csvPath = Join-Path $output " $domain `_Export_$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) .csv"
205205
206- if ($checkedGroups.Count -eq 0 ) {
207- Show-MessageBox " Select at least one group." " Warning" " Warning" ; return
208- }
209- if ($attrs.Count -eq 0 ) {
210- Show-MessageBox " Select at least one attribute." " Warning" " Warning" ; return
211- }
212-
213- $progress.Maximum = $checkedGroups.Count
214- $progress.Value = 0
215- $results = @ ()
206+ if ($checkedGroups.Count -eq 0 ) {
207+ Show-MessageBox " Select at least one group." " Warning" " Warning" ; return
208+ }
209+ if ($attrs.Count -eq 0 ) {
210+ Show-MessageBox " Select at least one attribute." " Warning" " Warning" ; return
211+ }
216212
217- foreach ($group in $checkedGroups ) {
218- try {
219- $members = Get-ADGroupMember - Identity $group - Server $domain - Recursive | Where-Object { $_.objectClass -eq ' user' }
220- foreach ($m in $members ) {
221- $user = Get-ADUser - Identity $m.DistinguishedName - Server $domain - Properties $attrs
222- $obj = [ordered ]@ { Domain = $domain ; Group = $group ; UserDN = $m.DistinguishedName }
223- foreach ($attr in $attrs ) { $obj [$attr ] = $user .$attr }
224- $results += New-Object PSObject - Property $obj
213+ $progress.Maximum = $checkedGroups.Count
214+ $progress.Value = 0
215+ $results = @ ()
216+
217+ foreach ($group in $checkedGroups ) {
218+ try {
219+ $members = Get-ADGroupMember - Identity $group - Server $domain - Recursive | Where-Object { $_.objectClass -eq ' user' }
220+ foreach ($m in $members ) {
221+ $user = Get-ADUser - Identity $m.DistinguishedName - Server $domain - Properties $attrs
222+ $obj = [ordered ]@ { Domain = $domain ; Group = $group ; UserDN = $m.DistinguishedName }
223+ foreach ($attr in $attrs ) { $obj [$attr ] = $user .$attr }
224+ $results += New-Object PSObject - Property $obj
225+ }
226+ } catch {
227+ Write-Log " Failed group ${group} : $_ " " ERROR"
225228 }
226- } catch {
227- Write-Log " Failed group ${group} : $_ " " ERROR"
229+ $progress.Value ++
228230 }
229- $progress.Value ++
230- }
231231
232- if ($results.Count -gt 0 ) {
233- $results | Export-Csv - Path $csvPath - NoTypeInformation - Encoding UTF8
234- Show-MessageBox " Export complete: $csvPath " " Done"
235- Start-Process $csvPath
236- } else {
237- Show-MessageBox " No results to export." " Info"
238- }
239- })
232+ if ($results.Count -gt 0 ) {
233+ $results | Export-Csv - Path $csvPath - NoTypeInformation - Encoding UTF8
234+ Show-MessageBox " Export complete: $csvPath " " Done"
235+ Start-Process $csvPath
236+ } else {
237+ Show-MessageBox " No results to export." " Info"
238+ }
239+ })
240240
241241Load- Groups
242242$form.Add_Shown ({ $form.Activate () })
0 commit comments