I am using this script below to imitate a flexible save file scenario and the code works fine in PowerShell console, but when I am trying to run it through invoke PowerShell activity it keeps on running without any output or error.
Script:
Add-Type -AssemblyName System.Windows.Forms
$saveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
$saveFileDialog.Filter = “All Files (.)|.”
$saveFileDialog.FileName = “defaultFileName.txt”
$saveFileDialog.InitialDirectory = “C:\Path\To\Your\Default\Directory”
$result = $saveFileDialog.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$selectedFilePath = $saveFileDialog.FileName
$selectedFilePath
} else {
“Dialog was canceled or closed without saving.”
}