# can Read-host -prompt pop up in a new window, something like Out-GridView ?

**URL:** <https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922>\
**Category:** PowerShell Help\
**Created:** [January 25, 2017, 5:04pm UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922 "2017-01-25T17:04:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsps](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@hsps](https://forums.powershell.org/u/hsps)\
**Post date:** [January 25, 2017, 5:04pm UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922/1 "2017-01-25T17:04:25Z")

</div>

When I prompt the user to provide input in PowerShell command window, I want to be able to prompt the user with messages in GUI pop-up windows instead of asking user to provide answers in PowerShell command window.

I am looking for a code that does the same job as Out-GridView. (i.e. gsv | Out-GridView). is the Out-GridView code simpler than writing Windows forms with PowerShell?

here is a sample script to backup and restore a Microsoft Edge (.EDB) database file, and Microsoft Edge Favorite bookmarks.  
Any suggestion or comment on how to improve this script in terms of making it shorter and more efficient would be greatly appreciated. Thank you

###Scripts only runs on Windows 10 version 10.0.10586 and above where Microsoft Edge database folder structure exists  
Set-ExecutionPolicy RemoteSigned -Force  
if((Get-WmiObject -Class win32\_operatingsystem).Version -lt ‘10.0.10586’){  
“This PowerShell script can be used on Windows 10 version ‘10.0.10586’ and above”;Start-Sleep -Seconds 10;exit}

$EdgeDatabaseFolder = “$env:LOCALAPPDATA\Packages\Microsoft.MicrosoftEdge\_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049\DBStore”  
If((Test-Path -Path $EdgeDatabaseFolder) -eq $false){  
"Open Microsoft Edge browser, and run this script again "}

if((Get-WmiObject -Class win32\_operatingsystem).Version -gt ‘10.0.10586’){“creating backup files”}  
#Script continues to run if the database folder structure exists, and creates a backup of Edge browser .edb file along with the #120712-0049 folder  
$EdgeDatabaseFolder = “$env:LOCALAPPDATA\Packages\Microsoft.MicrosoftEdge\_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049\DBStore”  
If((Test-Path -Path $EdgeDatabaseFolder) -eq $true){  
$EdgeDatabaseFile = “$env:LOCALAPPDATA\Packages\Microsoft.MicrosoftEdge\_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049\DBStore\spartan.edb”  
Copy-Item -Path $EdgeDatabaseFolder -Destination “$Home\Documents\Edge-Favorite-Backup-Before-Import” -Recurse  
$EdbBackUpFileName = (Get-Date -Format o) | foreach {$\_ -replace “:”,“.”}  
Rename-Item -Path $EdgeDatabaseFile -NewName (-join($EdbBackUpFileName + “.edb”))  
}

#Closes Microsoft Edge browser intances and imports spartan.edb file from backup to restore bookmarks  
“Importing your Edge browser and Favorite bookmarks from backup which are stored in spartan.edb file…”  
$EdbBackupFileToRestore = read-host -Prompt “Enter the file path to your Edge browser database (spartan.edb) backup file (i.e. C:\users\Win10\Documents\Backup\120712-0049\DBStore\spartan.edb)”  
if((Read-Host -Prompt “pressing ‘y’ will close all currently open Edge browser windows and processes on the machine where this script runs. Press ‘y’ to continue to restore your Edge spartan.edb file from backup)”) -eq ‘y’){  
Get-Process MicrosoftEdge\* | Stop-Process  
Copy-Item -Path $EdbBackupFileToRestore -Destination $EdgeDatabaseFolder -Force}  
if((Read-Host -Prompt “Your Edge browser bookmarks have been restored. It is recommended to Ctrl C to Exit the script here, however, to continue restoring previously cached icons and log files from backup, which may not be required, press y to continue or press Ctrl C to exit”) -eq ‘y’){  
$EdgeFolder = "$env:LOCALAPPDATA\Packages\Microsoft.MicrosoftEdge\_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049"  
$EdgeBackupFolderToRestore = read-host -Prompt “Enter the path to your '\120712-0049' Edge backup folder (i.e. C:\users\Win10\Documents\Backup\120712-0049)”  
$EdgeFavoritesCachedIconsDir = “$EdgeBackupFolderToRestore\Favorites”  
Copy-Item -Path $EdgeFavoritesCachedIconsDir -Destination “$EdgeFolder” -Recurse -Force  
}  
if((read-host -prompt “Restore is comlete. To roll back changes press ‘R’ or To exit the script press C”) -eq ‘r’){  
${GetIndexOf120712-0049} = $EdgeFolder.IndexOf(“120712-0049”)  
${Edge-nouser1-Folder} = $EdgeFolder.Remove(${GetIndexOf120712-0049})  
Copy-Item -Path $EdgeBackupFolderToRestore -Destination ${Edge-nouser1-Folder} -Recurse -Force -Confirm:$false  
} # End of script

“End of script”  
“#############”

---

<div class="post-metadata">

**Author:** ![nimms](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@nimms](https://forums.powershell.org/u/nimms)\
**Post date:** [January 25, 2017, 6:56pm UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922/2 "2017-01-25T18:56:17Z")

</div>

Hello, Hassan. Lookie here:

```
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$Message = "Enter the path to your '120712-0049' Edge backup folder (i.e. C:\users\Win10\Documents\Backup\120712-0049)"
$Title = "Enter the path"
$r = ''
while (-not $r) {
    $r = [Microsoft.VisualBasic.Interaction]::InputBox($Message, $Title)
}
$r
```

Well, you get the idea. 🙂 You can use Visual Basic’s **InputBox** in your PowerShell script. It gets installed with .NET Framework.

---

<div class="post-metadata">

**Author:** ![hsps](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@hsps](https://forums.powershell.org/u/hsps)\
**Post date:** [January 25, 2017, 11:18pm UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922/3 "2017-01-25T23:18:02Z")

</div>

Thank you. yes I got it.  
1- VS XAML file and dialog scripts  
2-.NET assemblies with native code

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [January 26, 2017, 5:06am UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922/4 "2017-01-26T05:06:34Z")

</div>

You’d do better to make the Y/N choices switch parameters and the path a parameter rather than using prompts like this

---

<div class="post-metadata">

**Author:** ![hsps](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@hsps](https://forums.powershell.org/u/hsps)\
**Post date:** [January 28, 2017, 3:44pm UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922/5 "2017-01-28T15:44:21Z")

</div>

Thanks. it made it shorter., something like this?

```
Restore-Edge-Favorites (
[parameter(Mandatory=$true,HelpMessage="file path to spartan.edb backup (i.e. E:\backup\120712-0049\DBStore\spartan.edb)")]$EdbBackupFileToRestore,
[parameter(Mandatory=$true,HelpMessage="folder path to '\120712-0049\' backup (i.e. E:\backup\120712-0049)")]$EdgeBackupFolder
){ 
if((Read-Host -Prompt "Close all Edge browsers, '
then press 'Y(for Yes)' to continue or N(for No) to exit") -eq 'y'){
Get-Process MicrosoftEdge* | Stop-Process
$EdgeDatabaseFolder = "$env:LOCALAPPDATA\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049\DBStore"
Copy-Item -Path $EdbBackupFileToRestore -Destination $EdgeDatabaseFolder -Force}
if((Read-Host -Prompt "Press Y(for Yes) to restore CachedIcons and logs or Press N(for No) to exit" -eq 'y')){
${120712-0049} = "$env:LOCALAPPDATA\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049\"
$CachedIconsDir = "$EdgeBackupFolder\Favorites"
Copy-Item -Path $CachedIconsDir -Destination "${120712-0049}" -Recurse -Force
}
}
Restore-Edge-Favorites
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/can-read-host-prompt-pop-up-in-a-new-window-something-like-out-gridview/7922/6 "2024-05-16T20:39:33Z")

</div>

Closed on May 16, 2024, 8:39pm UTC


