#http:
#https:
#https:
get-adgroup -filter
'GroupCategory -eq "Security"'
| sort name | select Name|Export-Csv -Path
$env
:temp\ADGroup.txt -NoTypeInformation
(Get-Content
$env
:temp\ADGroup.txt) -replace
'"'
,
''
| Set-Content
$env
:temp\ADGroup.txt
Import-Module activedirectory
#import Presentation framework
for
error message pop-up
Add-Type -AssemblyName PresentationCore,PresentationFramework
Function getADMember(
$groupName
)
{
try
{
Get-ADGroupMember
$groupName
-Recursive|select-object name,SamAccountName,distinguishedName,objectClass|Export-Csv -Path
$env
:temp\
$groupName
.csv -NoTypeInformation
#|Export-Csv -Path
$env
:temp\
$groupName
.csv -NoTypeInformation
#Out-GridView -
PassThru
|
invoke-item -Path
$env
:temp\
$groupName
.csv
}
catch
{
$ButtonType
= [System.Windows.MessageBoxButton]::OK
$MessageIcon
= [System.Windows.MessageBoxImage]::Error
$MessageBody
= $(
$_
.Exception.Message)
$MessageTitle
=
"Error"
$Result
= [System.Windows.MessageBox]::Show(
$MessageBody
,
$MessageTitle
,
$ButtonType
,
$MessageIcon
)
}
finally
{
}
}
#region Boring beginning stuff
[void] [System.Reflection.Assembly]::LoadWithPartialName(
"System.Windows.Forms"
)
[void] [System.Reflection.Assembly]::LoadWithPartialName(
"System.Drawing"
)
#endregion
#region begin to draw forms
$Form
= New-Object System.Windows.Forms.Form
$Form
.Text =
"Get AD Group Member"
$Form
.Size = New-Object System.Drawing.Size(300,170)
$Form
.StartPosition =
"CenterScreen"
$Form
.KeyPreview =
$True
$Form
.MaximumSize =
$Form
.Size
$Form
.MinimumSize =
$Form
.Size
$label
= New-Object System.Windows.Forms.label
$label
.Location = New-Object System.Drawing.Size(5,5)
$label
.Size = New-Object System.Drawing.Size(240,30)
$label
.Text =
"Type any group name"
$Form
.Controls.Add(
$label
)
$textbox
= New-Object System.Windows.Forms.TextBox
$textbox
.Location = New-Object System.Drawing.Size(5,40)
$textbox
.Size = New-Object System.Drawing.Size(165,25)
#
$textbox
.Text =
"Select source PC:"
$Form
.Controls.Add(
$textbox
)
$search_group
=
{
#region Actual Code
$statusBar1
.Text =
"Searching..."
$DLName
=
$textbox
.Text
getADMember(
$DLName
)
$statusBar1
.Text =
"Searching Complete"
#endregion
}
$OKButton
= New-Object System.Windows.Forms.Button
$OKButton
.Location = New-Object System.Drawing.Size(180,38)
$OKButton
.Size = New-Object System.Drawing.Size(50,23)
$OKButton
.Text =
"OK"
$OKButton
.Add_Click(
$search_group
)
$Form
.Controls.Add(
$OKButton
)
$result_label
= New-Object System.Windows.Forms.label
$result_label
.Location = New-Object System.Drawing.Size(5,65)
$result_label
.Size = New-Object System.Drawing.Size(240,30)
$result_label
.Text =
""
$Form
.Controls.Add(
$result_label
)
$statusBar1
= New-Object System.Windows.Forms.StatusBar
$statusBar1
.Name =
"statusBar1"
$statusBar1
.Text =
"Ready..."
$form
.Controls.Add(
$statusBar1
)
$Form
.Add_KeyDown({
if
(
$_
.KeyCode -eq
"Enter"
){&
$search_group
}})
$Form
.Add_KeyDown({
if
(
$_
.KeyCode -eq
"Escape"
)
{
$Form
.Close()}})
#endregion begin to draw forms
#Autocomplete region begins here
$textbox
.AutoCompleteSource =
'CustomSource'
$textbox
.AutoCompleteMode=
'SuggestAppend'
$textbox
.AutoCompleteCustomSource=
$autocomplete
#Importing from a file
Get-content -Path
$env
:temp\ADGroup.txt | % {
$textbox
.AutoCompleteCustomSource.AddRange(
$_
) }
#Autocomplete region ends here
#Show form
$Form
.Topmost =
$True
$Form
.Add_Shown({
$Form
.Activate()})
[void]
$Form
.ShowDialog()
You must be logged in to post a comment.