Nessuna descrizione

MCW-NAS-Search.ps1 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Add-Type -AssemblyName System.Windows.Forms
  2. # Create form
  3. $form = New-Object System.Windows.Forms.Form
  4. $form.Text = 'File Search'
  5. $form.Size = New-Object System.Drawing.Size(500,300) # Adjust form size here
  6. $form.StartPosition = 'CenterScreen'
  7. # Create label
  8. $label = New-Object System.Windows.Forms.Label
  9. $label.Location = New-Object System.Drawing.Point(10,20)
  10. $label.Size = New-Object System.Drawing.Size(480,20) # Adjust label size here
  11. $label.Text = 'Enter your search query:'
  12. $form.Controls.Add($label)
  13. # Create textbox
  14. $textBox = New-Object System.Windows.Forms.TextBox
  15. $textBox.Location = New-Object System.Drawing.Point(10,40)
  16. $textBox.Size = New-Object System.Drawing.Size(460,20) # Adjust textbox size here
  17. $form.Controls.Add($textBox)
  18. # Create button
  19. $button = New-Object System.Windows.Forms.Button
  20. $button.Location = New-Object System.Drawing.Point(10,70)
  21. $button.Size = New-Object System.Drawing.Size(75,23)
  22. $button.Text = 'Search'
  23. $button.Add_Click({
  24. $query = $textBox.Text
  25. $drives = @{
  26. 'H' = 'Hugh';
  27. 'I' = 'Charlie';
  28. 'K' = 'Kirk';
  29. 'S' = 'Spock';
  30. 'T' = 'Tom';
  31. 'U' = 'Jerry';
  32. 'Z' = 'Beta'
  33. }
  34. $outputBox.Text = ''
  35. foreach ($drive in $drives.Keys) {
  36. if (Test-Path "$drive`:\") {
  37. Get-ChildItem -Path "$drive`:\" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*$query*" } | ForEach-Object {
  38. $outputBox.Text += "`n$($_.Name) located on $($drives[$drive]) ($drive`:)"
  39. }
  40. }
  41. }
  42. })
  43. $form.Controls.Add($button)
  44. # Create output box
  45. $outputBox = New-Object System.Windows.Forms.TextBox
  46. $outputBox.Location = New-Object System.Drawing.Point(10,100)
  47. $outputBox.Size = New-Object System.Drawing.Size(460,160) # Adjust output box size here
  48. $outputBox.Multiline = $true
  49. $outputBox.ScrollBars = 'Vertical'
  50. $form.Controls.Add($outputBox)
  51. # Show form
  52. $form.ShowDialog()

Powered by TurnKey Linux.