L
L
L0ns2021-11-16 16:30:28
PowerShell
L0ns, 2021-11-16 16:30:28

Why is powershell form request information not displayed?

Colleagues, there is a task to view acl folders through powershell. I wanted to arrange it beautifully in windowed mode, but for some reason the information that is needed is not displayed, an empty field, help me figure out what I'm doing wrong? Apparently, somehow I wrote the function incorrectly ....

Script:

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

##############################################################################################################

function GetAclFolder {


  $Input = $inputBox.Text
  $Result = (get-acl $Input).access | select @{expression={$_.IdentityReference}; label='Кто имеет доступ'}, @{expression={$_.IsInherited}; label='Наследование прав'}, @{expression={$_.FileSystemRights}; label='Тип доступа'}

  $outputBox.Text = $Result
}


##############################################################################################################


$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Права доступа на папку"
$Form.Size = New-Object System.Drawing.Size(600,400)

##############################################################################################################


$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Введите путь к папке, Например C:\Temp"
$Label.Location = New-Object System.Drawing.Size(20,30)
$Label.BackColor = "Transparent"
$Label.AutoSize = $true

$Form.Controls.Add($Label)


##############################################################################################################

$inputBox = New-Object System.Windows.Forms.TextBox
$inputBox.Location = New-Object System.Drawing.Size(20,50)
$inputBox.Size = New-Object System.Drawing.Size(250,20)

$Form.Controls.Add($inputBox)

##############################################################################################################


$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(10,150)
$outputBox.Size = New-Object System.Drawing.Size(565,200)
$outputBox.MultiLine = $True

$Form.Controls.Add($OutputBox)


##############################################################################################################



$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(400,30)
$Button.Size = New-Object System.Drawing.Size(110,80)
$Button.Text = "Посмотреть права"

$Button.Add_Click( {GetAclFolder} )


$Form.Controls.Add($Button)



##############################################################################################################


[void] $Form.ShowDialog()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Bezrukov, 2021-11-16
@L0ns

Instead of the second TextBox ($outputbox) it is better to use ListVew or ListBox, then your script will be something like this:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
##############################
function GetAclFolder
{
  $InputText = $inputBox.Text
  $Result = (get-acl $InputText).access | Select-Object IdentityReference,IsInherited,FileSystemRights
  ForEach ($r in $Result)
  {
    $item = New-Object System.Windows.Forms.ListViewItem($r.IdentityReference.ToString())
    $item.SubItems.Add($r.IsInherited.ToString())
    $item.SubItems.Add($r.FileSystemRights.ToString())
    $listView.Items.AddRange($item)
  }
}
##############################
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Права доступа на папку"
$Form.StartPosition = "CenterScreen"
$Form.Width = 600
$Form.Height = 400
##############################
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Введите путь к папке, Например C:\Temp"
$Label.Location = New-Object System.Drawing.Size(20,30)
$Label.BackColor = "Transparent"
$Label.AutoSize = $true
$Form.Controls.Add($Label)
##############################
$inputBox = New-Object System.Windows.Forms.TextBox
$inputBox.Location = New-Object System.Drawing.Size(20,50)
$inputBox.Size = New-Object System.Drawing.Size(250,20)
$Form.Controls.Add($inputBox)
##############################
$listView = New-Object System.Windows.Forms.ListView
$listView.View = 'Details'
$listview.Location = New-Object System.Drawing.Size(10,150)
$listView.Width = 565
$listView.Height = 200
$listView.Columns.Add("Кто имеет доступ") | Out-Null
$listView.Columns.Add("Наследование прав") | Out-Null
$listView.Columns.Add("Тип доступа") | Out-Null
$Form.Controls.Add($listView)
##############################
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(400,30)
$Button.Size = New-Object System.Drawing.Size(110,80)
$Button.Text = "Посмотреть права"
$Button.Add_Click( {GetAclFolder} )
$Form.Controls.Add($Button)
##############################
$Form.ShowDialog() | Out-Null

Result
6193cbd24f814930639036.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question