I have powershell script that reads output from powershell command line and saves it into a hash.
When I try to get "sender-ip", the output is blank.
Below is the code
$args = (($args | % { $_ -join ", " }) -join " ")
foreach ($i in $args){
$line_array+= $i.split(",")
}
foreach ($j in $line_array){
$multi_array += ,@($j.split("="))
}
foreach ($k in $multi_array){
$my_hash.add($k[0],$k[1])
write-host $k
}
$Sender_IP = $my_hash.Get_Item("sender-ip")
Write-host 'sender-ip is' $Sender_IP
Here are the arguments passed into the script
script.ps1 Manager Last Name=Doe, discover-location=null, protocol=Clipboard, Resolution=null, file-owner=user, Employee Type=External Employee, endpoint-file-path=null, Title=null, discover-extraction-date=null, Sender-IP=10.10.10.10, Manager Business Unit=IT Services, Manager Phone=414-555-5555, Username=user, Division=Contractor, file-created-by=DOMAIN\user, file-owner-domain=DOMAIN
And this is the output
Manager Last Name Doe
discover-location null
protocol Clipboard
Resolution null
file-owner user
Employee Type External Employee
endpoint-file-path null
Title null
discover-extraction-date null
Sender-IP 10.10.10.10
Manager Business Unit IT Services
Manager Phone 414-555-5555
Username user
Division Contractor
file-created-by DOMAIN\user
file-owner-domain DOMAIN
sender-ip is
The code seems correct, what is missing?