Home > PowerShell > PowerShell – Quick way to iterate through a list of items

PowerShell – Quick way to iterate through a list of items

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
}
Advertisements
Categories: PowerShell Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: