JustScriptIt
Technical User
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
•sender-email
•sender-ip
•sender-port
•endpoint-user-name
•endpoint-machine-name
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
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
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
I strongly prefer to use powershell.
Thank you!
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
•sender-email
•sender-ip
•sender-port
•endpoint-user-name
•endpoint-machine-name
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:
param([string]$Sender_IP=$(**sender-ip**))
$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
$UserID
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
ignore
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
Python:
attributeMap = parseInput(args)
dateSent = attributeMap["sender-ip"]
I strongly prefer to use powershell.
Thank you!