I have a script to call an API endpoint to retrieve data from a hierarchy in an application.
This hierarchy has a few levels: Campus, Building, Floor To make it user friendly, I've written the script to compile a table which gets the names of the hierarchy level being queried into an array, and adds a number to the entry in a new array column (basically the array index, made human-readable)
The script writes the table to the terminal using a Format-Table
command, and then asks the user with a Read-Host
command to provide an input based on the prompt provided.
If I then call this script assigning it to a variable (to make the output manipulation easier) the prompt doesn't show, so you can provide values blindly and not achieve what you want.
For example, if I call the script directly I get this in the terminal window:
.\My-script-here.ps1
Number name
------ ----
1 Campus 1
2 Campus 2
Enter number of campus:
If I assign it to a variable, I get this:
$variable = .\My-script-here.ps1
Enter number of campus:
Is there a way to get the compiled table to appear when assigning the script to the variable?
Currently the line in the script is $Table | Format-Table -Property Number,Name
I've tried piping this to Write-Output
but that hasn't made a difference