PowerShell: CLI or GUI - what do you need or prefer?

PowerShell v1.0 is, of course, the console console. This does not require a GUI interface. If required, like the Exchange 2007 GUI, it is built on top of PowerShell. You can create your own GUI using Windows Forms in a PowerShell script. My question is: "Which PowerShell scripts or management tasks do you think are best used with even a simple GUI? What did you create winforms to run?"

0
command-line scripting powershell winforms automation
source share
6 answers

In response to the monkut suggestion, here is a simple function to get file paths using 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 to create a similar Select-Directory function, but the FolderBrowserDialog STA stream requirement is pretty hard to achieve in PowerShell v1.


Edit: Thanks to Gordon , a workaround to show 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 } } 
+3
source share

My favorite old gui tool for the command line shell was a directory selection tool that when exceued from the command line will open the gui directory selection dialog. Very useful when you need cd to another directory with a long path name.

I could not find the old exe tool that I used for failure. (In any case, this was a preliminary version) In addition, I am not familiar enough with powershell to understand how to call a dialog from powershell directly and do it cmd-let or something else, but here's what I’m saying that some python is mixed.

Here he is:

 PS D:\> $dir = & "C:\python25\python.exe" "C:\python25\selectdir.pyw"; cd $dir; # Directory selection dialog opens here, user selects the directory to goto. PS D:\NewDirectory> 

And python code:

 import Tkinter import tkFileDialog root = Tkinter.Tk() root.withdraw() dirname = tkFileDialog.askdirectory(parent=root) print dirname 

I want to use this tool again if anyone knows how to clean it, so I can just call a command like "cdir" or comment on something.

+1
source share

Isn't it mainly used by guys from powershell who want to make scripts there before passing them on to users or people who don't know anything about the console and how beautiful the pictures are?

0
source share

I would go to the PowerGUI site, which I'm sure you already know about Jeff. What users do is what I would consider as an example of powershell splicing and GUI. The ability to generate a list of objects then expand into the hierarchical structure of the objects or run scripts on the object. This is where I see the GUI interface.

0
source share

I hope for some examples here because I am sure that there are many tasks that I could delegate if they had a nice user interface and could be used with the mouse.

But as for adding a user interface, I have a problem thinking about a place where it is not. Most of the examples that I can think of are either simply dumbfounded or reveal a selected section of an existing user interface. Typically, this is just a different view of existing data that is not there, or difficult to see in the provided management console. Or they extend some functions with looping or pipelining (you can still use the mouse to change the names of 200 files if you want). Almost everything I did, which is still in use, is one-shot scenarios or somewhere in the form of a scheduled task.

I'm waiting for ideas :)

0
source share

In fact, thinking about it more. In the examples that I saw using the graphical interface, they appear to be multiple input fronts, which is much simpler than a command line with several switches, which can be quite long and difficult to visualize.

0
source share

All Articles