Does anyone have any articles, suggestions, recommendations, etc. for when creating cmdlets that you want to be executed locally and/or remotely.
Just as an example. If I wanted to create a cmdlet that installs software, but I want to be able to use that same cmdlet to install software on a list of machines, one of those machines being my local computer what are some best practices for setting up your functions to do this?
I am currently building out a new module and find myself struggling with how to complete this.
Do some research on Powershell repositories. Ideally, you would setup an internal PowershellGet repository that would allow you to go to any system with PowershellGet capabilities and simply do a Install-Module MyModule. Powershell 5+ has native capabilities and Powershell 3-4 require additional software to enable this functionality.
Some other things to note, you should check out Chocolatey, which is providing *nix software installation capabilities.
Lastly, if you are trying to do DevOps and want to ensure software is installed on these systems, you can take a look at Powershell Desired State Configuration (DSC). This is more of a policy driven approach that ensures settings, software, etc. are the same against multiple systems.
So the same cmdlet runs but gets data from a remote computer and from the local computer. I want to understand how this works, so I can follow best practices when creating a cmdlet that does something similar.
That has more to do with how you design your script/function/cmdlet. Use Get-Help and check out the following help topics:
about_Functions
about_Functions_Advanced
about_Parameters
about_Functions_Advanced_Parameters
Those are good topics to look at. Check out the other topics listed under ‘SEE ALSO’ at the end of each one. Also check out the PowerShell Style and Practices Guide. Hope that helps!