Skip to main content

Posts

Showing posts from January, 2014

Querying for nested folders with PowerCLI

Have you fought trying to query nested, duplicate-named folders?  Hopefully this will help solve the problem!  Suppose you have a VM folder-tree similar to this:   So, how do you get the "\dotcom\linux\dev" folder using PowerCLI?  If you query for just "dev" then you can get an array of folders.    You can parse through the array and, using the parent object, traverse the tree backwards validating the folder names.  But, what if you have 100s of folders?  In my opinion, this is not an optimal approach.   We really need to do this: This is great case for  recursion .  In my words, recursion is a "stack" of operations.  When an operation completes its result is used by the next operation in the "stack".  Most importantly there has to be base-case which causes the last operation in the stack to return a valid result.  Then each operation can be popped off the "stack" and its result can be used by the previous opera