O'Reilly logo

PowerShell for Office 365 by Prashant G Bhoyar, Martin Machado

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cmdlets

Cmdlets were the original way of extending PowerShell. Cmdlets have basically the same functionality as functions (PowerShell cmdlets are comparable with advanced functions), but they are implemented in C# and packaged in .NET assemblies.

It is more common to implement scripts as functions in PowerShell files as they can be edited easily. Still, cmdlets might be useful in a few scenarios:

  • There is a significant investment in C# as a scripting language
  • The code needs to be protected (.NET assemblies can be obfuscated)

In the following example, we define the GetListCommand cmdlet. It inherits from the Cmdlet class from the System.Management.Automation namespace.

To consume SharePoint, the Cmdlet class accepts a ClientContext parameter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required