Choice to out put to a file

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:

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??

Luther,
Welcome to the forum. :wave:t4:

The phrase to search for would be “PowerShell prompt for choice”. And here are some search hits:

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

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