Just a heads-up.the list software does a good job with mail handling. If it
recognizes email problems (too many undelivered emails) it quarantines the
email address and eventually removes it from the list if it cannot be
resolved within a specific time period.

 

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com]
On Behalf Of Michael B. Smith
Sent: Thursday, October 19, 2017 7:56 PM
To: powershell@lists.myitforum.com
Subject: [powershell] FW: Powershell array question and formatting question

 

Hmph.

 

I was kicked-off the PowerShell list for some reason.

 

Here is my response.

 

From: Michael B. Smith 
Sent: Thursday, October 19, 2017 2:20 PM
To: ntsys...@lists.myitforum.com <mailto:ntsys...@lists.myitforum.com> ;
powershell@lists.myitforum.com <mailto:powershell@lists.myitforum.com> 
Subject: RE: Powershell array question and formatting question

 

An array in Windows is of fixed size. If you want something of variable
size, you use a list or a table. For example, this shows a list which
contains strings:

 



 

Now, there is also something called an ArrayList, but let's not make things
confusing.

 

PowerShell has lots of syntactic sugar around hash tables and ordered hash
tables. They might be useful to you.

 

The formatting question is a little more complicated. That's because the
Test-Connection cmdlet is changing the name of the "Destination" column
behind your back. (The way it does that is complicated, and trust me, you
don't really want to know.) To get what you want:

 



 

But if you are happy with the column being named "Address", which is the
true name of the variable:

 



 

From: listsad...@lists.myitforum.com <mailto:listsad...@lists.myitforum.com>
[mailto:listsad...@lists.myitforum.com] On Behalf Of Raymond Peng
Sent: Thursday, October 19, 2017 1:34 PM
To: powershell@lists.myitforum.com <mailto:powershell@lists.myitforum.com> ;
ntsys...@lists.myitforum.com <mailto:ntsys...@lists.myitforum.com> 
Subject: [NTSysADM] Powershell array question and formatting question

 

Hi All,

 

Still picking up powershell so please let me know if you see any obvious
blunders: I see it say the collection is of a fixed size but how do I
remove?

 

I have declared an array with $array="name1","name2", etc.

I can access each element with $array[0].

 

I can use $array += "name5,"name6" but I can not figure out how to remove an
element

I have tried the Remove method without any luck as well as -= 

 

PS C:\WINDOWS\system32> $array.Remove("cxsupportsystems")

Exception calling "Remove" with "1" argument(s): "Collection was of a fixed
size."

At line:1 char:1

+ $array.Remove("cxsupportsystems")

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [],
MethodInvocationException

    + FullyQualifiedErrorId : NotSupportedException

 

 

PS C:\WINDOWS\system32> $array

kcfileserver

wnweb01

pvfile01

corpcxtsgp01

cxsupportsystems 

 

Lastly - formatting question:

 

Is there any way to just crop out the rest and keep the destination /
IPv4Address info? I tried format-table / select-object but it does not do
what I want. I've tried piping after the test-connection in the scriptblock
but output is not what I want

 

 

PS C:\WINDOWS\system32> foreach ($comp in $array){Test-Connection $comp
-Count 1}

 

Source        Destination     IPV4Address      IPV6Address
Bytes    Time(ms) 

------        -----------     -----------      -----------
-----    -------- 

L-SM-RPENG1   kcfileserver    172.29.133.130
32       62       

L-SM-RPENG1   wnweb01         172.29.118.101
32       66       

L-SM-RPENG1   pvfile01        172.29.171.28
32       72       

L-SM-RPENG1   corpcxtsgp01    172.29.118.164
32       70       

L-SM-RPENG1   cxsupportsys... 10.2.1.238
32       55       

 

 

 


Thank you,

 

Ray

 

 

 



Reply via email to