OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Building separate objects from lengthy arrays in Powershell

  • Thread starter Thread starter greenGob19
  • Start date Start date
G

greenGob19

Guest
I have an array of IPs that I want to add on to a URL. The array can be very long and the URL can only accept so many characters, so I need to break up the array of IPs ONLY when it reaches the max characters.

Let's say the max number of characters for a URL is 40. Either I want to base it off that character limit, or I could go by a certain number of IPs (for this example below it'd be 2).

`

Code:
$IPs = @('1.1.1.1', '2.2.2.2', '3.3.3.3', '4.4.4.4', '5.5.5.5')
$URL = 'https://test.com/ips=$IPs' # this is 25 characters
if ($IPs -ge 15) {
foreach ($IP in $IPs) {
    $IPs| Where-Object $_.count -gt 2
    Invoke-RestMethod -Method Get -Uri $URL

    }
}

`

I'm trying to build this loop to be able to accomplish this task and am completely stuck.
<p>I have an array of IPs that I want to add on to a URL. The array can be very long and the URL can only accept so many characters, so I need to break up the array of IPs ONLY when it reaches the max characters.</p>
<p>Let's say the max number of characters for a URL is 40. Either I want to base it off that character limit, or I could go by a certain number of IPs (for this example below it'd be 2).</p>
<p>`</p>
<pre><code>$IPs = @('1.1.1.1', '2.2.2.2', '3.3.3.3', '4.4.4.4', '5.5.5.5')
$URL = 'https://test.com/ips=$IPs' # this is 25 characters
if ($IPs -ge 15) {
foreach ($IP in $IPs) {
$IPs| Where-Object $_.count -gt 2
Invoke-RestMethod -Method Get -Uri $URL

}
}
</code></pre>
<p>`</p>
<p>I'm trying to build this loop to be able to accomplish this task and am completely stuck.</p>
Continue reading...
 

Latest posts

Top