I want to create a GUI in Powershell where the user selects a path to save an empty txt file. For this I use SaveFileDialog. When I run the code below, the file is created temporarily. It is not saved permanently. What do I need to change?
Function fileSave
{
$OpenFileDialog = New-Object System.Windows.Forms.SaveFileDialog
$OpenFileDialog.CheckPathExists = $true
$OpenFileDialog.CreatePrompt = true;
$OpenFileDialog.OverwritePrompt = true;
$OpenFileDialog.initialDirectory = $initialDirectory
$Directory = $OpenFileDialog.FileName = 'NewFile'
$OpenFileDialog.Title = 'Choose directory to save the output file'
$OpenFileDialog.filter = "Text documents (.txt)|*.txt"
# Show save file dialog box
if($OpenFileDialog.ShowDialog() -eq 'Ok'){
$NewFile = New-Item -Path "$Directory" -ItemType File -Force
}