R – PowerShell: CLI or GUI – which do you need or prefer?

automationcommand-linepowershellscriptingwinforms

PowerShell v1.0 is obviously a console based administrative shell. It doesn't really require a GUI interface. If one is required, like the Exchange 2007 management GUI, it is built on top of PowerShell. You can create your own GUI using Windows Forms in a PowerShell script. My question is, "What sort of PowerShell scripts or management tasks do you think would be best served with the addition of even a simple graphical interface? What have you created winforms to accomplish?"

Best Solution

In answer to monkut's suggestion, here's a simple function to get file paths using the WindowsForms OpenFileDialog:

[void] [Reflection.Assembly]::LoadWithPartialName( 'System.Windows.Forms' )

function Select-File( [string]$initialDirectory=$pwd, [switch]$multiselect ) {
  $dialog = New-Object Windows.Forms.OpenFileDialog
  $dialog.ShowHelp = $true  # http://tinyurl.com/6cnmrr
  $dialog.InitialDirectory = $initialDirectory
  $dialog.Multiselect = $multiselect

  if( $dialog.ShowDialog( ) -eq 'OK' ) { $dialog.FileNames }
  $dialog.Dispose( )
}

I also tried creating a similar Select-Directory function, but FolderBrowserDialog's STA thread requirement is rather difficult to achieve in PowerShell v1.


Edit: Thanks to Gordon, here's a workaround to show the FolderBrowserDialog using COM:

function Select-Directory( ) {
  $app = New-Object -COM Shell.Application
  $directory = $app.BrowseForFolder( 0, "Select Directory", 0 )
  $path = $directory.Self.Path
  if( $path ) { return $path }
}