Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Method invocation failed because [System.Object[]] doesn't contain a method named 'split'

$
0
0

Hello,

When I try to use the split method, it works in PowerShell v3 and not in v2! While I search this in forums, I found relevant posts but not sure why it generate error message in v2!

Here is the code snippet. My intention is to read list of groups and separate them by comma. Any further help would be greatly appreciated. Thank you.

$UserGroups = @(Read-Host " ").split(',') | % {$_.trim()}

For example, if I enter: 123,456

In PowerShell v3, it shows:

123

456

In PowerShell v2, it shows:

Method invocation failed because [System.Object[]] doesn't contain a method named 'split'.At C:\Scripts\test.ps1:20 char:41+

$UserGroups = @(Read-Host " ").split <<<< (',') | % {$_.trim()}    + CategoryInfo

: InvalidOperation: (split:String) [], RuntimeException    + FullyQualifiedErrorId : MethodNotFound


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>