+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, Powerhsell - runn command based on the option? in Coding and Web Development; Hi, I would like it so when you run a power shell script that it will present 4 options to ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,779
    Thank Post
    865
    Thanked 1,665 Times in 1,450 Posts
    Blog Entries
    11
    Rep Power
    442

    Powerhsell - runn command based on the option?

    Hi,

    I would like it so when you run a power shell script that it will present 4 options to the end user. Depending on what option the user picks it will then run 1 command. all 4 options will have different commands.

    Does that make sense please?

    Thanks

  2. #2

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    Makes sense, and simple enough really. Simple version below.

    Write-Host "Press 1 for option 1"
    Write-Host "Press 2 for option 2"

    Read-Host $command

    switch ($command) {
    1 {do stuff for command 1}
    2 {do stuff for command 2}
    default {Write-Host "Didn't recognise the command"}
    }

    If you want to force them to choose an option you can stick the whole thing in a while loop, and use the default case to set a variable so that it'll loop again.

  3. Thanks to jamesb from:

    Rawns (6th September 2013)

  4. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,779
    Thank Post
    865
    Thanked 1,665 Times in 1,450 Posts
    Blog Entries
    11
    Rep Power
    442
    Thanks for the help

  5. #4

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    No problem. Out of curiousity, what's it for?

  6. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,779
    Thank Post
    865
    Thanked 1,665 Times in 1,450 Posts
    Blog Entries
    11
    Rep Power
    442
    When we add a computer to AD we have a couple of things to do. Like create it in SCCM, add mac address and add a group. So making a little powershell script to speed the process up.

    The options will be

    Staff Desktop
    Staff Laptop
    Student Desktop
    Student Laptop

    Thanks

  7. Thanks to FN-GM from:

    jamesb (6th September 2013)

  8. #6

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,779
    Thank Post
    865
    Thanked 1,665 Times in 1,450 Posts
    Blog Entries
    11
    Rep Power
    442
    hi @jamesb there is a slight error i notice it should be something like This:

    Write-Host "Press 1 for option 1"
    Write-Host "Press 2 for option 2"

    $command = Read-Host "Please Enter An Option"

    switch ($command) {
    1 {do stuff for command 1}
    2 {do stuff for command 2}
    default {Write-Host "Didn't recognise the command"}
    }

    Apart from that all is good and it seems to work

    Thanks

  9. #7

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    Oops.

  10. #8

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,779
    Thank Post
    865
    Thanked 1,665 Times in 1,450 Posts
    Blog Entries
    11
    Rep Power
    442
    Apart from that perfect Thanks again.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 9
    Last Post: 6th October 2010, 03:54 PM
  2. How to Map a Shared Drive based on the users OU??
    By soveryapt in forum Windows Server 2000/2003
    Replies: 1
    Last Post: 29th April 2010, 01:00 PM
  3. redirect a user based on the OU Sharepoint
    By mtdmitchell in forum Virtual Learning Platforms
    Replies: 11
    Last Post: 27th March 2010, 09:06 AM
  4. Site based on the edugeek template
    By plexer in forum EduGeek Joomla 1.0 Package
    Replies: 6
    Last Post: 5th December 2007, 12:58 PM
  5. Another Site based on the edugeek template
    By linkazoid in forum Web Development
    Replies: 6
    Last Post: 26th November 2007, 11:18 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •