Проблема в $groups
при запуске |где члены -подобны $users
Я не уверен, является ли $users
правильной переменной, поскольку она не может поместить то, что нужно в текстовое поле. Когда я запускаю скрипт, ничего не появляется, кроме имени пользователя, где я также хочу увидеть группы, к которым принадлежит пользователь. Пожалуйста, помогите.
Функция resultWGroups () {$ y = $ GenTextbox.Text $ SecondGenFormwGroups = New-Object System.Windows.Forms.Form $ SecondGenFormwGroups.Text = 'Скрипт' $ SecondGenFormwGroups.Autosize = $ true $ SecondGenFormwositionSt. = 'centerscreen'
$TexBoxwGroups= New-Object System.Windows.Forms.TextBox
$TexBoxwGroups.Size= New-Object System.Drawing.Size(500,230)
$TexBoxwGroups.Multiline= $true
$TexBoxwGroups.text =''
$TexBoxwGroups.ScrollBars='Vertical'
$TexBoxwGroups.Location = New-Object System.Drawing.Point(20,140)
$ListUsers = New-Object System.Windows.Forms.ComboBox
$ListUsers.Width = 600
$ListUsers.add_selectedindexchanged({$TexBoxwGroups.Text=$listusers.Text
$Groups
})
## searching for groups
## also the issue
$Groups = Get-ADGroup -Properties * -Filter * -SearchBase "dc=example,dc=com" | where members -like *$Users* | Select
-Property Name
## searching for users
$Users = Get-ADUser -filter * -SearchBase "dc=example,dc=com" |Select-String -Pattern $y
Foreach ($User in $Users){
$ListUsers.Items.Add($User)
}
$SecondGenFormwGroups.Controls.Add($TexBoxwGroups)
$SecondGenFormwGroups.AllowDrop = $true
$SecondGenFormwGroups.Controls.Add($ListUsers)
$SecondGenFormwGroups.ShowDialog()
}
## This is just the box with out the groups
Function result (){
$x = $GenTextbox.Text
$SecondGenForm= New-Object System.Windows.Forms.Form
$SecondGenForm.Text= 'Script'
$SecondGenForm.Autosize=$true
$SecondGenForm.StartPosition= 'centerscreen'
$SecondGenForm.AutoScaleMode.value__.Equals(3)
$ComboBox = New-Object System.Windows.Forms.ComboBox
$ComboBox.Width = 600
##searching for users
$Users = Get-ADUser -filter * -SearchBase "dc=example,dc=com" |Select-String -Pattern $x
Foreach ($User in $Users){
$ComboBox.Items.Add($User);
}
$SecondGenForm.Controls.Add($ComboBox)
$SecondGenForm.ShowDialog()
$SecondGenForm.Dispose()
}
Function search-aduser () {
$GenForm= New-Object System.Windows.Forms.Form
$GenForm.Text= 'Script'
$GenForm.StartPosition= 'centerscreen'
$GenForm.Size = New-Object System.Drawing.Size(300,200)
##
$Username= New-Object System.Windows.Forms.Label
$Username.Text= 'What is user name'
$Groupschoice= New-Object System.Windows.Forms.Label
$Groupschoice.Location= New-Object System.Drawing.Point(90,65)
$Groupschoice.Text= 'do you want groups'
$GenTextbox= New-Object System.Windows.Forms.TextBox
$GenTextbox.Location = New-Object System.Drawing.Point(10,40)
$GenTextbox.Size = New-Object System.Drawing.Size(260,20)
$GenTextbox.AcceptsReturn =$true
$YesButton= new-object System.Windows.Forms.Button
$YesButton.text = 'yes'
$YesButton.Location = New-Object System.Drawing.Point(75,90)
$YesButton.Size = New-Object System.Drawing.Size(50,20)
$YesButton.add_click({resultwGroups})
##some buttons
$NoButton= new-object System.Windows.Forms.Button
$NoButton.text = 'no'
$NoButton.Location = New-Object System.Drawing.Point(140,90)
$NoButton.Size = New-Object System.Drawing.Size(50,20)
$NoButton.add_click({result})
##bulding the form
$GenForm.Controls.Add($Groupschoice)
$GenForm.AcceptButton = $YesButton
$GenForm.Controls.Add($YesButton)
$GenForm.Controls.Add($NoButton)
$GenForm.Controls.Add($GenTextbox)
$Username.AutoSize=$true
$Groupschoice.AutoSize=$true
$GenForm.Controls.Add($Username)
$GenForm.Controls.Add($GenTextbox.Select())
$GenForm.ShowDialog()
$GenForm.Dispose()
}