Still Working Through the Codeplex Autointaller Script

We’re still trying to decode the SharePoint 2010 Autoinstaller Script from CodePlex.

We got the Throw thing figured out thanks to TechNet which offers this little demo:

function Get-XMLFiles
   param ($path = $(throw "The Path parameter is required."))
   dir -path $path\* -include *.xml -recurse | sort lastwritetime
   |  ft lastwritetime, attributes, name  -auto

Which is all good except trying to figure out what to do with it. I found this from our new best friend Dr. Tobias. Of course, we know saving this into a .ps1 script will make it run but, in the console, you have to learn to do multi-line entry and Dr. Tobias covers that straight away.

So looking that the function we’ll create, we see we enclose the code in {curley braces} and we have a param section. Here we drop our variable $path and we set it’s initial value to $(Throw “blah blah blah”) What this does is poke the Throw to the processor unless it’s replaced by an alternative at runtime.

Hence, get-XMLFiles (‘C:\’) will return all the .xml files on your C: drive.

You’ll also see that the -include option filters the return to .xml files, the -recurse option makes it dig down into folders and sub-folders, the  sort sorts the output and the ft formats the output into a nice table with the designated headers. Note also that the parameter is passed inside parenthesis and single quotes. I presume you’d separate multiple paramerters with a comma.

Essentially, in the Get-XMLFiles function, it’s give me a path or I’ll barf. I’ve been there.

In the AutoInstaller script, the script itself has a parameter block, so when the script is called, it better get passed a configuration file or it’s barf city. I’ve been there too.

The one thing I don’t know is how to list the function code after it’s built. I presume I can just rebuild it with new code but I don’t know how to get what I’ve got in there to make minor edits. So I turned to our new best friend Lee who talks about environment variables here. From what he says, I figured out that a get-content function:<function name> will display the code supporting a given function.

Progress. That’s good.




Comments are closed.