|
@@ -0,0 +1,62 @@
|
|
1
|
+# Create a GUI form with a dropdown menu for disks and a dropdown menu for volumes
|
|
2
|
+$xaml = @"
|
|
3
|
+<Window
|
|
4
|
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
5
|
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
6
|
+ Title="DiskPart GUI" Height="200" Width="300">
|
|
7
|
+ <StackPanel>
|
|
8
|
+ <ComboBox x:Name="disks" Width="100" Height="25" Margin="5" SelectionChanged="disks_SelectionChanged"/>
|
|
9
|
+ <ComboBox x:Name="volumes" Width="100" Height="25" Margin="5" SelectionChanged="volumes_SelectionChanged" IsEnabled="False"/>
|
|
10
|
+ <StackPanel Orientation="Horizontal">
|
|
11
|
+ <Button x:Name="cleanButton" Width="75" Height="25" Margin="5" Content="Clean Disk" Click="cleanButton_Click" IsEnabled="False"/>
|
|
12
|
+ <Button x:Name="formatButton" Width="75" Height="25" Margin="5" Content="Format Volume" Click="formatButton_Click" IsEnabled="False"/>
|
|
13
|
+ <Button x:Name="extendButton" Width="75" Height="25" Margin="5" Content="Extend Volume" Click="extendButton_Click" IsEnabled="False"/>
|
|
14
|
+ </StackPanel>
|
|
15
|
+ </StackPanel>
|
|
16
|
+</Window>
|
|
17
|
+"@
|
|
18
|
+
|
|
19
|
+# Load the XAML into a WPF object
|
|
20
|
+$reader = (New-Object System.Xml.XmlNodeReader $xaml)
|
|
21
|
+$form = [Windows.Markup.XamlReader]::Load($reader)
|
|
22
|
+
|
|
23
|
+# Add event handlers for the buttons and dropdown menus
|
|
24
|
+$form.Add_cleanButton_Click({
|
|
25
|
+ # Code to run when the "Clean Disk" button is clicked
|
|
26
|
+ # Use the Diskpart command to clean the selected disk
|
|
27
|
+ diskpart /s "clean disk $($form.disks.SelectedItem)"
|
|
28
|
+})
|
|
29
|
+
|
|
30
|
+$form.Add_formatButton_Click({
|
|
31
|
+ # Code to run when the "Format Volume" button is clicked
|
|
32
|
+ # Use the Diskpart command to format the selected volume
|
|
33
|
+ diskpart /s "format fs=ntfs label=$($form.volumes.SelectedItem) quick"
|
|
34
|
+})
|
|
35
|
+
|
|
36
|
+$form.Add_extendButton_Click({
|
|
37
|
+ # Code to run when the "Extend Volume" button is clicked
|
|
38
|
+ # Use the Diskpart command to extend the selected volume
|
|
39
|
+ diskpart /s "extend size=100000"
|
|
40
|
+})
|
|
41
|
+
|
|
42
|
+$form.Add_disks_SelectionChanged({
|
|
43
|
+ # Code to run when the "disks" dropdown menu selection is changed
|
|
44
|
+ # Use the Diskpart command to list the volumes on the selected disk
|
|
45
|
+ $volumes = (diskpart /s "list volume" | Select-String "Volume ###") -replace "Volume ###",""
|
|
46
|
+ $form.volumes.ItemsSource = $volumes
|
|
47
|
+ $form.volumes.IsEnabled = $true
|
|
48
|
+ $form.cleanButton.IsEnabled = $true
|
|
49
|
+})
|
|
50
|
+
|
|
51
|
+$form.Add_volumes_SelectionChanged({
|
|
52
|
+# Code to run when the "volumes" dropdown menu selection is changed
|
|
53
|
+ $form.formatButton.IsEnabled = $true
|
|
54
|
+ $form.extendButton.IsEnabled = $true
|
|
55
|
+})
|
|
56
|
+
|
|
57
|
+# Populate the "disks" dropdown menu
|
|
58
|
+$disks = (diskpart /s "list disk" | Select-String "Disk ###") -replace "Disk ###",""
|
|
59
|
+$form.disks.ItemsSource = $disks
|
|
60
|
+
|
|
61
|
+# Show the GUI form
|
|
62
|
+$form.ShowDialog() | Out-Null
|