I have a power shell script that when run will prompt the user to:
- Select a folder location
- select a file name
- enter credentials
This then exports those credentials in a xml file. Although this requires 3 prompts to the user before is complete. Looking to find if there is a better way to approach this. For example, having a single prompt for the user.
###########################################################
# Create a file containing encrypted credentials
###########################################################
clear
Function Get-Folder($initialDirectory)
{
#User selected folder location
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null
$path = New-Object System.Windows.Forms.FolderBrowserDialog
$path.Description = "Select a folder"
$path.rootfolder = "MyComputer"
if($path.ShowDialog() -eq "OK")
{
$location += $path.SelectedPath
}
#User selected file name
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'File Name'
$msg = 'Please enter your file name'
$text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
#Open prompt for user to enter credentials and export to xml file
Get-Credential | Export-Clixml "$location\Credentials-$text.xml"
}
Get-Folder