Set the Path

Although we called this "Set the Path", it is a bit of an understatement.  Sure "\\server\c$\Scripts" is where you could set the path for your Powershell script library, but that isn't really what the following line is doing.


1) The variable $scripts is going to get the result of the operation to the right of the = 

2) Get-ChildItem...   ...-recurse -include *.ps1 is somewhat self explanatory, but it is worth being clear that -recurse will search all sub folders that we specified in our path, also -include *.ps1 specifies that we only want to include the Powershell files in our search

3) The most confusing part of this line can be the | (pipe).  This takes the results from the left side of the pipe, and passes them to the command on right side of the pipe.  In this case we take all of the get-childItem results and pass them into a "ForEach-Object" loop that puts the FullName back into the variable $scripts variable.

In the end, if you want to run the script, the only thing you will need to change is the path.  Trust me, we realize that this script is sloppy.  If you download the full code, you will also need to modify the path of lines: 1, 52,57, and 58 to the path that works in your environment.  

No comments:

Post a Comment