Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Powershell - now to extract name of variable passed to script

Powershell - now to extract name of variable passed to script

Powershell - now to extract name of variable passed to script

I am writing powershell script to interface with an external software program our company is using

The script needs to take in value of the input parameter and do something.

But the problem is, this external software pushes many input parameters with the names

I only need the value for sender-ip. But my problem is

1.I don't know in which order the external program is inputting the parameters to the script
2.Powershell naming convention does not allow for a hyphen, so it's not like I can just start using sender-ip without getting an error The term 'sender-ip' is not recognized as the name of a cmdlet, function, script file, or operable program.
Here is my script so far

CODE --> Powershell

$eventList = @()
Get-EventLog "Security" -computername $Sender_IP `
        | Where -FilterScript {$_.EventID -eq 4624 -and $_.ReplacementStrings[4].Length -gt 10 -and $_.ReplacementStrings[5] -notlike "*$"} `
        | Select-Object -First 2 `
        | foreach-Object {
            $row = "" | Select UserName, LoginTime
            $row.UserName = $_.ReplacementStrings[5]
            $row.LoginTime = $_.TimeGenerated
            $eventList += $row
$UserId = $eventList[0].UserName


See, when I manually invoke foo.psl *ip_address*, everything works well. But if I call the program without parameter, I get error.

How to write code such as

CODE -->

if name of input variable is **sender-ip** 
   do something
else if name of input variable is something different 

I am not evaluating value of the input parameter, I want to capture the input parameter that is named sender-ip, and from there I will run the script and evaluate.

I hope I explained my question well.

In the past, people interfaced with this third party program using Python script, where you can simply write the following

CODE --> Python

attributeMap = parseInput(args) 
dateSent = attributeMap["sender-ip"] 

I strongly prefer to use powershell.

Thank you!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close