Extending a PowerShell Function
If you’ve been keeping up with the articles, you’ve seen how I went from a script block to a basic PowerShell function. This is a stand-alone function, meaning it isn’t part of a module. You would need to save the function to a file and dot-source the file, as I discussed in an earlier article. Before we move on to revising the function to an advanced function that accepts pipeline input, I want to take a few minutes to cover a few other things you can do with your PowerShell function to make it easier to use.
Defining an Alias
After loading your function into your PowerShell session, you might find it easier to use with an alias. An alias saves you some typing at the console. Or it can make it easier to use when the function has an unwieldy “official” name. You might have a function called Invoke-CompanyWindowsServerBackup
. The function name is meaningful, which is good, but that’s a lot to type. Tab completion helps, but it might be just as easy to have an alias of Run-WinBackUp
. Aliases don’t have to be cryptic two or three-letter words.