0

Friends.

Probably a really nice easy one.

On this technet thread 'BigTeddy' wrote a wonderful little script to get a dynamic menu from a Get-Service query.

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/74c34d41-1cf6-494e-8fe2-13827c3b7a4d/create-dynamic-menu-system-with-powershell?forum=ITCG

I'm doing something similar and would like to know how to list both the Name and Status in the menu.

Here's the code:

$processes = Get-Process
$menu = @{}
for ($i=1;$i -le $processes.count; $i++) 
{ Write-Host "$i. $($processes[$i-1].name)"
$menu.Add($i,($processes[$i-1].name)) }

[int]$ans = Read-Host 'Enter selection'
$selection = $menu.Item($ans) ; Get-Process $selection

Is that something that can easily be achieved? I'm somewhere around a basic user for PowerShell and so can't figure out where, if anywhere, to put the .Status

Thanks

1

2 Answers 2

7

I guess you have gotten a reply or figured this one out?

Switched get-process to get-service

$services = Get-Service
$menu = @{}
for ($i=1;$i -le $services.count; $i++) 
{ Write-Host "$i. $($services[$i-1].name),$($services[$i-1].status)" 
$menu.Add($i,($services[$i-1].name))}

[int]$ans = Read-Host 'Enter selection'
$selection = $menu.Item($ans) ; Get-Service $selection
Sign up to request clarification or add additional context in comments.

Comments

1

For others looking for this post, I was having some issues with

$selection = $menu.Item($ans)

If you need other properties of the original array / collection try

$selection = $services[$ans-1]

Then you can access

$selection.DisplayName
$selection.StartMode

etc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.