Using a PowerShell Quote List Function to Work with an Array of Strings

Reblogged from Mississippi PowerShell User Group:

Recently, during one of our test user group meetings that Rohn and I had, I was using an example of storing multiple server names into an array to then work with them. This is how I would normally accomplish this task, that is unless I pulled the names directly from Active Directory:

ql1

Rohn showed me the way he has been accomplishing this sort of task which requires less typing:

ql2

I tweaked Rohn’s example a little since I prefer to split on spaces, but it’s basically the same example:

ql3

With further testing, I determined I could use the split parameter first and save a few more characters even though the tabbed expansion or intellisense in the ISE didn’t like this, it still worked:

ql4

Rohn said he recently learned about using a function called a quote list where you can define the function and then simply pass your items to it with no punctuation required:

ql5

I decided to record a short video of this process:

Don’t forget to join us on Tuesday, March 12th at 8:30pm Central Time for our user group meeting which is held online via Microsoft Lync. We’ll be giving away two ebook copies of the PowerShell Deep Dives book.

µ

Update:
I asked Rohn to take a look at this post and see what he thought. He said he learned about the quote list function while reading the “Windows PowerShell in Action, Second Edition” book written by Bruce Payette.

µ

1 Comment

  1. matthew

    The other way that helps for me is to pull a list from a sharepoint list. Why you ask. Maybe I only want to do something to a specific environment which I notate in sharepoint. This also makes for a great way to develop a audit and inventory set of scripts through powershell.

    Reply

Leave a Reply

%d bloggers like this: