설명 없음

ChatGPT-DiskpartGUI-test1.ps1 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. # Load the XAML into a WPF object
  19. $reader = (New-Object System.Xml.XmlNodeReader $xaml)
  20. $form = [Windows.Markup.XamlReader]::Load($reader)
  21. # Add event handlers for the buttons and dropdown menus
  22. $form.Add_cleanButton_Click({
  23. # Code to run when the "Clean Disk" button is clicked
  24. # Use the Diskpart command to clean the selected disk
  25. diskpart /s "clean disk $($form.disks.SelectedItem)"
  26. })
  27. $form.Add_formatButton_Click({
  28. # Code to run when the "Format Volume" button is clicked
  29. # Use the Diskpart command to format the selected volume
  30. diskpart /s "format fs=ntfs label=$($form.volumes.SelectedItem) quick"
  31. })
  32. $form.Add_extendButton_Click({
  33. # Code to run when the "Extend Volume" button is clicked
  34. # Use the Diskpart command to extend the selected volume
  35. diskpart /s "extend size=100000"
  36. })
  37. $form.Add_disks_SelectionChanged({
  38. # Code to run when the "disks" dropdown menu selection is changed
  39. # Use the Diskpart command to list the volumes on the selected disk
  40. $volumes = (diskpart /s "list volume" | Select-String "Volume ###") -replace "Volume ###",""
  41. $form.volumes.ItemsSource = $volumes
  42. $form.volumes.IsEnabled = $true
  43. $form.cleanButton.IsEnabled = $true
  44. })
  45. $form.Add_volumes_SelectionChanged({
  46. # Code to run when the "volumes" dropdown menu selection is changed
  47. $form.formatButton.IsEnabled = $true
  48. $form.extendButton.IsEnabled = $true
  49. })
  50. # Populate the "disks" dropdown menu
  51. $disks = (diskpart /s "list disk" | Select-String "Disk ###") -replace "Disk ###",""
  52. $form.disks.ItemsSource = $disks
  53. # Show the GUI form
  54. $form.ShowDialog() | Out-Null

Powered by TurnKey Linux.