Collin Stump Collin Stump - 1 year ago 142
PowerShell Question

Difference between [datatype] and [datatype[]]

When casting a datatype for a variable, what does the extra empty square brackets do?

For example, in defining a parameter for a function, I have noticed these two ways of casting a data type for that parameter:




What purpose does the empty square brackets in the second example serve?

Answer Source

The parameter in the second example accepts a list of strings (an array), the parameter in the first example only a single string.

This works in both cases:

-computername 'foo'

This works just in the second case:

-computername 'foo', 'bar'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download