PowerShell newbie RRS feed

  • General discussion

  • I am attempting to write a script to prompt the user for a UserID and then query a spreadsheet for that UserID to see if it is present.  The problem I am having is getting the multiple lines of script to work together.  Here is what I have so far.

    This was my first attempt when entering the UserID (longm) manually and it works and returns the name.

    PS U:\> $csv = Import-Csv C:\DUMPITDS_20170927.csv
    $csv | where {$_.RMID -eq "longm"} | % FirstName
    $csv | where {$_.RMID -eq "longm"} | % LastName

    This was my attempt to prompt for user input, which works as well.

    $Username = Read-Host -Prompt 'Please Enter UserID'

    So my issue now is that I want to put those things together and first prompt the user for the "UserID", and then plug that input into the script above in place of "longm" and return the first and last name on the same line if possible.  Any suggestions?  I feel like I'm making this harder than it has to be.

    • Changed type Bill_Stewart Tuesday, November 7, 2017 10:18 PM
    • Moved by Bill_Stewart Tuesday, November 7, 2017 10:19 PM This is not "scripts on demand"
    Wednesday, September 27, 2017 6:15 PM

All replies

  • First you need to learn basic PowerShell:

    Learn PowerShell: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276

    Guessing will not get you anywhere with complex technologies.

    $csv | Where{$_.RMID -eq $username} | select FirstName, LastName


    Wednesday, September 27, 2017 6:28 PM
  • I was thrown into this with no warning and no knowledge except for some VB about 20 years ago.  Thanks for your help!
    Wednesday, September 27, 2017 6:48 PM
  • That worked, but when you run it the window closes immediately.  Is there a way to keep it open to show the results?  Also, what if the name is not found?  Will it just error out or is there an easy "if,then" line I can add that says If "null", then return "Name Not Found" or something like that.
    Wednesday, September 27, 2017 6:54 PM
  • As noted above.  You must take the time to learn the basics.  We will not write your code  for you one line at a time.  The forum is not designed to provide personal tutorials.


    Wednesday, September 27, 2017 6:57 PM
  • Thanks I guess.  The main page said to ask here to get your scripting problems solved.  I had a basic script that got me what I wanted, I was just missing how to put it together.  I'll check out the videos when I have an extra few hours to burn, but that doesn't help me today.  I appreciate your time for the 1 liner.
    Wednesday, September 27, 2017 7:10 PM
  • Don't be lazy.  We are not a free scripting forum.  The assumption is that you are a technician and not just a user.  If you are or want to be a tech then you will need to learn PowerShell.  Now is better than later.  If you just want someone to solve your problems then consider hiring a consultant.


    Wednesday, September 27, 2017 7:13 PM
  • I'm a desktop technician (hardware/software).  I was thrown into a project group and this landed on my plate.  I just don't have the time to learn powershell in the next 2 days or I would.   My employer refuses to pay consultant prices when they can make us do the work for peanuts.  LOL

    Thanks again for your help.  At least I can get them the answer, they just have to run it in the powershell window.  I'm good with that as it gets them the answer they need.

    Wednesday, September 27, 2017 7:27 PM
  • Nonsense.  No employer would tell you that you have to do something you are not rained to do.  If an employer is telling you to do something that you are not trained for then you need to get a new job with a sane employer. This is how bad things happen in technology and it is just an excuse that is overused by so many.  It is unhelpful and is not a way to get free scripts.

    For free scripts go here: http://gallery.technet.microsoft.com


    • Edited by jrv Wednesday, September 27, 2017 7:36 PM
    Wednesday, September 27, 2017 7:35 PM
  • Believe me, I wish it were nonsense.  I work for a large municipality that is known for being the "leanest" around.  They do not pay for training here.  I am 40 years old so I can't really start a new job hunt now. 
    Wednesday, September 27, 2017 8:49 PM
  • I would recommend you make a case for why training is needed and present it to your employer. If this is critical to the business, they will need to pay for what they need either by providing training for you or by hiring a consultant.

    Unfortunately this forum isn't a "script on demand" service. If you need someone to write code for you, you can post a request on the request page (you should be able to find a link at the top of this page), but there's no guarantee that someone has time to do this for you.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 27, 2017 10:28 PM