none
how to write a PowerShell script that asks users to choose between four items: RRS feed

  • Question

    1. See a list of processes on the system
    2. See a list of services on the system
    3. Send a ping
    4. Double a number

    Write the script to implement each choice:

      • If the user picks the first option, display a list of processes on the system.
      • If the user picks the second option, display a list of services on the system.
      • If the user picks the third option, ask the user for an IP address or FQDN (fully qualified domain name) to ping, and then send a ping using the appropriate PowerShell cmdlet (not the ping utility).
      • If the user picks the fourth option, ask the user for a number, and then display the output like this: Your original number was 5, but now it’s 10.
    Kindly assist me with how to do this assignment if you can ASAP!
    Saturday, June 15, 2019 11:43 PM

All replies

  • We do not write Homework scripts on request here. You should ask a specific question about code you wrote and you've got stuck with.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Saturday, June 15, 2019 11:59 PM
    Saturday, June 15, 2019 11:59 PM
  • Kids are really dumb and lazy these days.  They get an assignment and immediately look for someone to do it for them.  This is why most companies are having a hard time hiring.

    When I was vetting applicants I would fins so many that couldn't answer basic questions about computers and computing.  This has gotten much worse recently.

    "Assignments " mean just that. It is a directive to the student or employee to perform a required task.  Students and employees who cannot understand this or cannot perform end up flipping hamburgers.

    To be fair, there are many kids and entry level people who are exceptionally talented.  They are because they put in an effort to learn and understand.  Unfortunately too many are not capable of thinking for themselves.  This is really sad.

    This Forum is for   Scripting   Questions Rather than script requests

    How to ask   questions in a technical forum

    Forum for Script   requests

    Microsoft   Script Gallery

          Microsoft Virtual     Academy - Getting Started with Microsoft PowerShell

          PowerShell Documentation

          PowerShell Style   Guidelines


    \_(ツ)_/

    Sunday, June 16, 2019 12:26 AM
    Moderator
  • I would think that a good teacher would not just ask to 'write stuff' but also ask the student how or why they ended up with the particular solution.

     Anyway...to 'assist' with how to do this assignment in the most basic of ways, here are the building blocks you'd need:

    #1:
    Get-Process
    
    #2:
    Get-Service
    
    #3:
    Test-Netconnection
    
    #4:
    [int]$i*2
    
    # Present a rather lame text-based menu:
    Write-Host 'Press 1 for option 1'
    Write-Host 'Press 2 for option 2'
    $value = Read-Host -Prompt 'enter something'
    Switch ($value)
    {
        default {'Invalid or no input'}
        1 {'you picked 1'}
        2 {'you picked 2'}
    }

    Monday, June 17, 2019 11:25 AM
  • I would think that a good teacher would not just ask to 'write stuff' but also ask the student how or why they ended up with the particular solution.

     Anyway...to 'assist' with how to do this assignment in the most basic of ways, here are the building blocks you'd need:

    that is not the correct answer or the correct way to do this. It may be a way but it is not what the instructor is asking. In this case help is not helpful for a student in a structured class.


    \_(ツ)_/

    Monday, June 17, 2019 1:22 PM
    Moderator
  • The way i read it, it is.

    "Have some sort of menu interface that outputs things based on user choice."

    As you would know, there are a multitude of ways to do this, either to build a menu, collect information, ask for input and / or output data.

    The OP is asking for a complete script, i just pointed out some bits and pieces that could help. How to put it together is for the him/her to figure out. 

    I thought you didn't like answers that take away all the thinking for the OP ? :)

    Monday, June 17, 2019 1:36 PM
  • Exactly my point.  You do not know which method the instructor is referring to.  I suggest that it is not the method you postulated and that will be confusing to the OP.

    The reason we don't do homework problems is because it does not help the student or the instructor because it we cannot be aligned with the lesson objectives.

    If a student asks a single simple question then it is OK to suggest how to use PowerShell help or the net to find possible answers.

    When a student posts a complete homework assignment and ask for someone to do it for them they need to be pushed back.  This is the same as cheating on an exam.  It should never be encouraged or tolerated.


    \_(ツ)_/

    Monday, June 17, 2019 1:51 PM
    Moderator
  • You are correct that i don't know the exact level of complexity the instructor expects. I made an assumption based on the information that was there.  For me, it gives the impression that the expectation is for something fairly basic. 

    I agree entirely though. 

    Tuesday, June 18, 2019 6:17 AM