Skip to content

Instantly share code, notes, and snippets.

@talatham
Created June 12, 2013 14:50
Show Gist options
  • Save talatham/5765958 to your computer and use it in GitHub Desktop.
Save talatham/5765958 to your computer and use it in GitHub Desktop.
Save to a file specified by a user dialog.
# ------ FUNCTION --------------
Function Set-Filename
# Set file name for saving export
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
$SaveFileDialog.Filter = "Text files (*.txt)|*.txt"
$SaveFileDialog.initialDirectory = "c:\"
if ($SaveFileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK)
{ $SaveFileDialog.FileName }
}
# ------ USAGE -------
$filename = Set-FileName
"some output text" | out-file $filename - append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment