Chapter 37. Proxy functions

 

This chapter covers

  • Understanding proxy functions
  • Creating proxy functions
  • Adding and removing parameters

Proxy functions are a neat—if little-used—aspect of PowerShell. A proxy is someone with the authority to act as you. A proxy function lets you replace a PowerShell command or function with a custom version while leveraging the internal functionality of the original. They’ve also been called “wrapper functions,” which is a good description, because they “wrap around” existing commands to provide a sort of custom interface to them.

37.1. The purpose of proxy functions

Proxy functions are often used as a way of restricting or enhancing a PowerShell command. For example, you might take away parameters from a command so that potentially dangerous functionality is disabled. Or you might add parameters to a command, enhancing its functionality.

PowerShell’s implicit remoting capability, which we discussed in chapter 10, utilizes proxy functions. When you import commands from a remote computer, you’re creating local proxy functions. They’re very sparse functions: They contain enough functionality to take whatever parameters you type, pass them to the remote machine, and execute the command there. But they make it look like the commands are available locally on your computer.

37.2. How proxy functions work

37.3. Creating a basic proxy function

37.4. Adding a parameter

37.5. Removing a parameter

37.6. Turning it into a function

37.7. Summary