# Choice to out put to a file

**URL:** <https://forums.powershell.org/t/choice-to-out-put-to-a-file/19029>\
**Category:** PowerShell Help\
**Created:** [April 6, 2022, 12:37pm UTC](https://forums.powershell.org/t/choice-to-out-put-to-a-file/19029 "2022-04-06T12:37:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luther](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/luther/32/2328_2.png) [@Luther](https://forums.powershell.org/u/Luther)\
**Post date:** [April 6, 2022, 12:37pm UTC](https://forums.powershell.org/t/choice-to-out-put-to-a-file/19029/1 "2022-04-06T12:37:02Z")

</div>

I am a desktop tech. I write small scrips for my co-workers to do easy tasks like join a domain or gather information from a device. I am a beginner(ish) with powershell.

I was wondering if there was a way to have Powershell to ask you if you would like to write the information to a file after displaying it on the screen.

Simple Example:

```auto
Write-Host "This will get you the current logged in user" -ForegroundColor Red -BackgroundColor Yellow

$device = Read-Host "Type in the device ID here"
Get-WmiObject –ComputerName $device –Class Win32_ComputerSystem | Select-Object UserName

Write-host "Would you like to write this to a file"

What comes next??

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 6, 2022, 12:47pm UTC](https://forums.powershell.org/t/choice-to-out-put-to-a-file/19029/2 "2022-04-06T12:47:41Z")

</div>

Luther,  
Welcome to the forum. 👋🏽

> [@Luther](#):
>
> I was wondering if there was a way to have Powershell to ask you if you would like to write the information to a file after displaying it on the screen.

The phrase to search for would be “PowerShell prompt for choice”. And here are some search hits:  
[https://kpatnayakuni.com/2019/01/15/just-a-tip-6-prompt-for-choice-in-powershell/](https://kpatnayakuni.com/2019/01/15/just-a-tip-6-prompt-for-choice-in-powershell/)

[https://social.technet.microsoft.com/wiki/contents/articles/24030.powershell-demo-prompt-for-choice.aspx](https://social.technet.microsoft.com/wiki/contents/articles/24030.powershell-demo-prompt-for-choice.aspx)

[https://4sysops.com/archives/read-host-and-the-choicedescription-class-prompt-for-user-input-in-powershell/](https://4sysops.com/archives/read-host-and-the-choicedescription-class-prompt-for-user-input-in-powershell/)

> **[PSHostUserInterface.PromptForChoice Method (System.Management.Automation.Host)](https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.host.pshostuserinterface.promptforchoice?view=powershellsdk-7.3.0&viewFallbackFrom=powershellsdk-7.0.0)**
>
> Presents a dialog allowing the user to choose an option from a set of options.

BTW: When you post code, sample data, console output or error messages please format it as code using the _preformatted text_ button ( **\</\>** ). Simply place your cursor on an empty line, click the button and paste your code.  
Thanks in advance  
[How to format code in PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif)

---

<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:18pm UTC](https://forums.powershell.org/t/choice-to-out-put-to-a-file/19029/3 "2024-05-16T20:18:03Z")

</div>


