Get-Ryan

[PowerShell] Get-FileName

Oct 6th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Get-FileName {
  2.     [cmdletbinding()]
  3.  
  4.     param(
  5.         [String]
  6.         $StartDirectory,
  7.  
  8.         [String]
  9.         $Title
  10.     )
  11.    
  12.     [Void]([System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms"))
  13.  
  14.     $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
  15.     $OpenFileDialog.InitialDirectory = $StartDirectory
  16.     $OpenFileDialog.Filter = "All files (*.*)|*.*"
  17.     If($Title){
  18.         $OpenFileDialog.Title = $Title
  19.     }
  20.     [Void]($OpenFileDialog.ShowDialog())
  21.    
  22.     $OpenFileDialog.FileName
  23.  }
Advertisement
Add Comment
Please, Sign In to add comment