PowerShell modules

In the previous chapters, we have used files to package scripts, functions to easily reuse our code, and the modules for each of the Office 365 APIs. As your code gets more complex, the logical progression is to implement your own modules.

Advantages of modules are as follows:

  • Package functionality for distribution and reuse
  • Provides documentation infrastructure
  • Can have private and public functions

We will get started by reviewing the available commands to work with modules.

To showcase the advantages of modules, we will create an example. Our module will support a dashboard in SharePoint Online. The dashboard will display daily sales for each of the products in the database.

So that we do not deviate too much from the scope of this chapter, we will use the AdventureWorks schema (http://msftdbprodsamples.codeplex.com/releases/view/55330). This database contains a simple model of products, customers, and sales that we will use to calculate daily sales.

In this scenario, we calculate the product daily sales and update a SharePoint list with that information. Our module will contain functions to read from a SQL Server database and to connect to SharePoint Online and update a list:

If you can expose your database publicly, this scenario could be better implemented with SharePoint Business Connectivity Services (BCS). BCS allows direct integration with SQL Server and other data sources.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.235.176