PowerShell scripts are most valuable when they can be used with different data sets.  Command line parameters provide a dynamic way to change the the data sets on each use.  Alternatively, importing data from static files within the script rather than from the command line is easier when the information:

  1. remains the same for long periods
  2. must be in exactly the same format every time
  3. may be provided by the end user through, for example, a spreadsheet

The example application to import Service Channel work orders into SharePoint has these examples:

The Subcontractor default states and email list

The CSV file is FencingDefaultSubcontractors.csv. 

It has:

  1. the subcontractor name
  2. the state where the subcontractor operates
  3. the subcontractor email address

This meets all three criteria.  It changes infrequently.  It must always be in this format.  The fencing manager adds and deletes subcontractors from the file in Excel.

The Service Channel Work Orders Properties Map

The CSV file is SCCustomMap.csv. 

 

It has all the property display names from the source custom list (the headings) and the corresponding target list static names (the body).

This matches the first two criteria.  The map was painstakingly crafted when is was created.  It will rarely be changed.  It must always be in this format.  If it changes, the mapping will fail or omit properties.  

Noted that either of these could have been submitted as a parameter. Using the subcontractor list as the example:

$FencingSubcontractors = Import-CSV .\FencingDefaultSubcontractors.csv

The $FencingSubcontractors would be the variable submitted to the input parameter.

Adding this to the command line on every use is additional work for something that does not change often.  However, you do not have to open the program to add subcontractors as would have been the case if the script had the values hard-coded.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>