To add a little glamour to your scripts, here are a few lines of code that display a folder selector dialog. When a user selects a folder, your script receives the selection and can work with the selected path:- Add-Type -AssemblyName System.Windows.Forms
- [System.Windows.Forms.Application]::EnableVisualStyles()
-
- $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
- $null = $FolderBrowser.ShowDialog()
- $Path = $FolderBrowser.SelectedPath
-
- "You selected: $Path"
复制代码 Note the first two lines: they are not necessary when you run the code inside the ISE editor, but you do need them inside the powershell.exe. So keep these lines to make sure your code runs in all PowerShell hosts.
http://powershell.com/cs/blogs/tips/archive/2013/12/09/create-a-folder-selector.aspx |