9 Working outside of PowerShell

 

This chapter covers

  • Different ways to interact with resources outside of PowerShell
  • Using COM objects to interact with other applications
  • How to call local executables from PowerShell
  • Working with remote API

While PowerShell is a very robust language with multiple different integrations and custom modules, there are still some situations in which you need to work with something outside of PowerShell. This can range from calling separate executables to remote API calls and interacting directly with Component Object Module (COM) objects and Dynamic Link Library (DLL) files. As you will see, PowerShell has specially built cmdlets to deal with each one of these situations.

In this chapter, you will learn how to interact with different resources to solve one of the biggest problems in IT: system documentation (or the lack thereof). You will create a script that will populate a Word document using the Word COM object. You will then use PowerShell to gather information about your local computer and enter that data in the Word document.

Then, taking it further, you will use a remote REST API to get your external IP address and location information for the document. Then, finally, you will call a Python script to create a time-series graph that you can insert into the document. The process is illustrated in figure 9.1.

Figure 9.1 Write computer information to a Word document automation flow

9.1 Using COM objects and .NET Framework

9.1.1 Importing Word objects

9.1.2 Creating a Word document

9.1.3 Writing to a Word document

9.1.4 Adding tables to a Word document

9.2 Building tables from a PowerShell object

9.2.1 Converting PowerShell objects to tables

9.2.2 Converting PowerShell arrays to tables

9.3 Getting web data

9.3.1 API keys

9.4 Using external applications