Archive

Posts Tagged ‘split’

PowerShell – Quick way to iterate through a list of items

29th September, 2016 Leave a comment

In PowerShell, I sometimes I want to quickly iterate through a list of items that another system has produced. One option would be to export the data to a file and read it in, but sometimes it’s not practical or may be quite complicated to parse the file. As a “quick and dirty” solution, it’s possible to create a string spanning multiple lines. We can then use the split method to iterated through each string.

 

$data = ('65c43d1cb95b8646a0a8d1342d0e9326
946018fb0b250146a7625cc743d47377
72163af67ac45146836c62b7760aee28
e6fe3309096e024fa6a8809093c19cf3
097fcd70c2cebd43b67cc237ec0b1d43
b196d288b2fcc14ca0422e2eeb14410b')

$guids = $data.split("`n")

foreach ($guid in $guids) {
   $guid
}
Categories: PowerShell Tags: ,