The result looks like this:复制代码
- function Get-Something
- {
- param
- (
- [Parameter(Mandatory=$true)]
- $Path
- )
- "You entered $Path"
- }
PS > Get-Something cmdlet Get-Something at command pipeline position 1 Supply values for the following parameters: Path: |
http://powershell.com/cs/blogs/tips/archive/2014/02/06/mandatory-parameter-with-a-dialog.aspx复制代码
- function Get-Something
- {
- param
- (
- $Path = $(
- Add-Type -AssemblyName System.Windows.Forms
- $dlg = New-Object -TypeName System.Windows.Forms.OpenFileDialog
- if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileName } else { throw 'No Path submitted'}
- )
- )
- "You entered $Path"
- }
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |