How to define auto ranges in powershell

Welcome Forums General PowerShell Q&A How to define auto ranges in powershell

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 years, 7 months ago.

  • Author
    Posts
  • #25252

    Inactive
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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"}

The topic ‘How to define auto ranges in powershell’ is closed to new replies.