Hi Scripting guys,
I am having some problems displaying my arrays. I have various arrays containing IP addresses that I want to display like so..
FAILED 1 FAILED 2 FAILED 3
xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx
etc..
I then want to output this to a txt file or html file
.
When type the array in I get a list horizontal
xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx etc..
I thought the best way to overcome this would be to create a custom object so I did the following...
$Myobject =@() $obj = New-Object System.Object $obj | Add-Member -type NoteProperty -Name 1FAILED -Value $1FAILED $obj | Add-Member -type NoteProperty -Name 2FAILED -Value $2FAILED $myobject += $obj
When I display this variable It displays as follows
1FAIL
2FAIL
----------
----------------
{xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx......... {xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx ............
So my problem with this is its listing the address the wrong way and cutting off lots of addresses, I had a play around with formatting but I still couldnt get it to display these in a list.
My next thought was to split the arrays with a foreach loop...
$myobject =@()
foreach ($1FAIL in $CS1FAIL) {
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name 1FAIL -Value $1FAIL
$myobject += $obj
}
foreach ($2FAIL in $CS2FAIL) {
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name CS2FAIL -Value $2FAIL -Force
$myobject += $obj
}When I display $myobject I get my list of 1FAIL but 2FAIL doesnt appear and when I do $myobject | gm 2FAIL does not exist.
When I display $obj I only get a single IP address not the whole list (it only takes the last one)
on the plus side $myobject does display like so..
1FAIL
----------
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
etc
Any help would be appreciated, my goal is to have an output that will display the date and time followed by the list of failed IP addresses in a format which is suitable.
Thanks in advance