How to define auto ranges in powershell

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 1 year, 8 months ago.

  • Author
    Posts
  • #25252
    Profile photo of
    Anonymous

    Hi,
    Likewise

    PS C:\> 1..60 
    

    The above sort of input gives 1 to 60 automatically, I want to define my own specified data to auto range.

    For Example if I can define the data like below,
    'data1','data2','data3','data4','data5','data6','data7','data8','data9' ,'data10'

    The above data should come when I say...

    PS C:\> data1..data10
    
  • #25253
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    The range operator only works with numbers – in fact integers apparently

    If you want to define other things you'll need to code it

    $data = 'data1','data2','data3','data4','data5','data6','data7','data8','data9' ,'data10'
    $data[0..9]

    or

    $data[2..5]

    or

    0..9 | foreach {"$($data[$psitem])plusmore"}

You must be logged in to reply to this topic.