none
Setting Environment Variable not pulling in certain portion of script RRS feed

  • Question

  • We have multiple domain controllers and when a user gets locked out constantly it is a bit of a process to login to that domain controller, pull the event logs, and search through that way. I looked at a few ways to automate this process in powershell and tweaked it a bit to work the way we need it to. I am trying to make this a simplified process for people who will use this script, currently I have:

    $DC = Read-Host "Domain Controller"
    $Account = Read-Host "Username"
    Get-WinEvent -ComputerName $DC -FilterHashtable @{Logname='Security';Data='$Account'} -MaxEvents 4 | Format-List -Property ID, TimeCreated, MachineName, Message

    This seems to work perfectly for what we need except when entering the information in response to Read-Host for $Account. The $DC pulls correctly but the $Account doesn't (I found this out by entering the user's username in the data field instead of $Account and the script worked correctly). Any Ideas on how to get this to work?

    Tuesday, April 21, 2015 1:59 PM

Answers

  • @{Logname='Security';Data=$Account }

    No quotes required.


    \_(ツ)_/



    • Edited by jrv Tuesday, April 21, 2015 2:21 PM
    • Marked as answer by Rick Wobig Tuesday, April 21, 2015 2:27 PM
    Tuesday, April 21, 2015 2:20 PM

All replies

  • @{Logname='Security';Data=$Account }

    No quotes required.


    \_(ツ)_/



    • Edited by jrv Tuesday, April 21, 2015 2:21 PM
    • Marked as answer by Rick Wobig Tuesday, April 21, 2015 2:27 PM
    Tuesday, April 21, 2015 2:20 PM
  • Thank you! The answer is always that easy huh :)
    Tuesday, April 21, 2015 2:27 PM
  • Most answers are easy.  It is the questions that are hard.  If you had asked the right question you would have seen the answer immediately.

    Ask, "What is the difference between single and double quotes?"  When and why do variables need quotes?  Why and when do strings need quotes? 

    These are all PowerShell 101.  You must learn and understand to use PowerShell effectively


    \_(ツ)_/

    Tuesday, April 21, 2015 2:38 PM