1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- # Create a GUI form with a dropdown menu for disks and a dropdown menu for volumes
- $xaml = @"
- <Window
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="DiskPart GUI" Height="200" Width="300">
- <StackPanel>
- <ComboBox x:Name="disks" Width="100" Height="25" Margin="5" SelectionChanged="disks_SelectionChanged"/>
- <ComboBox x:Name="volumes" Width="100" Height="25" Margin="5" SelectionChanged="volumes_SelectionChanged" IsEnabled="False"/>
- <StackPanel Orientation="Horizontal">
- <Button x:Name="cleanButton" Width="75" Height="25" Margin="5" Content="Clean Disk" Click="cleanButton_Click" IsEnabled="False"/>
- <Button x:Name="formatButton" Width="75" Height="25" Margin="5" Content="Format Volume" Click="formatButton_Click" IsEnabled="False"/>
- <Button x:Name="extendButton" Width="75" Height="25" Margin="5" Content="Extend Volume" Click="extendButton_Click" IsEnabled="False"/>
- </StackPanel>
- </StackPanel>
- </Window>
- "@
-
- # Load the XAML into a WPF object
- $reader = (New-Object System.Xml.XmlNodeReader $xaml)
- $form = [Windows.Markup.XamlReader]::Load($reader)
-
- # Add event handlers for the buttons and dropdown menus
- $form.Add_cleanButton_Click({
- # Code to run when the "Clean Disk" button is clicked
- # Use the Diskpart command to clean the selected disk
- diskpart /s "clean disk $($form.disks.SelectedItem)"
- })
-
- $form.Add_formatButton_Click({
- # Code to run when the "Format Volume" button is clicked
- # Use the Diskpart command to format the selected volume
- diskpart /s "format fs=ntfs label=$($form.volumes.SelectedItem) quick"
- })
-
- $form.Add_extendButton_Click({
- # Code to run when the "Extend Volume" button is clicked
- # Use the Diskpart command to extend the selected volume
- diskpart /s "extend size=100000"
- })
-
- $form.Add_disks_SelectionChanged({
- # Code to run when the "disks" dropdown menu selection is changed
- # Use the Diskpart command to list the volumes on the selected disk
- $volumes = (diskpart /s "list volume" | Select-String "Volume ###") -replace "Volume ###",""
- $form.volumes.ItemsSource = $volumes
- $form.volumes.IsEnabled = $true
- $form.cleanButton.IsEnabled = $true
- })
-
- $form.Add_volumes_SelectionChanged({
- # Code to run when the "volumes" dropdown menu selection is changed
- $form.formatButton.IsEnabled = $true
- $form.extendButton.IsEnabled = $true
- })
-
- # Populate the "disks" dropdown menu
- $disks = (diskpart /s "list disk" | Select-String "Disk ###") -replace "Disk ###",""
- $form.disks.ItemsSource = $disks
-
- # Show the GUI form
- $form.ShowDialog() | Out-Null
|