Browse Source

Add 'MCW-NAS-Search.ps1'

Ethan 1 year ago
parent
commit
1e8d664298
1 changed files with 58 additions and 0 deletions
  1. 58
    0
      MCW-NAS-Search.ps1

+ 58
- 0
MCW-NAS-Search.ps1 View File

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

Powered by TurnKey Linux.