A better way to slice an array (or a list) in powershell
问题 How can i export mails adresses in CSV files in a range of 30 users for each one . I have already try this $users = Get-ADUser -Filter * -Properties Mail $nbCsv = [int][Math]::Ceiling($users.Count/30) For($i=0; $i -le $nbCsv; $i++){ $arr=@() For($j=(0*$i);$j -le ($i + 30);$j++){ $arr+=$users[$j] } $arr|Export-Csv -Path ($PSScriptRoot + "\ASSFAM" + ("{0:d2}" -f ([int]$i)) + ".csv") -Delimiter ";" -Encoding UTF8 -NoTypeInformation } It works but, i think there is a better way to achieve this