You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been searching the web for any guidelines, examples or best practices for when you want to create functions within or not within a module that allows for local and remote execution, but I haven't found anything.
A good example is the Get-Service cmdlet. If you specify the ComputerName parameter, the cmdlet knows how to handle executing this the specified host. If the ComputerName parameter is not used, then the cmdlet executes on the local computer.
Any help or guidance is really appreciated.
Thanks,
Michael
The text was updated successfully, but these errors were encountered:
This is a great question! I hope some others will pitch in thoughts ...
From my point of view, it seems that very few of these types of command will ever be written by third parties -- they only truly make sense when the thing you're working against has a built-in method of remote execution that is not WSMan, or is inherently remote anyway (e.g. REST commands like the Azure modules, or commands based on CIM or DCOM APIs).
Obviously if the command needs to execute PowerShell on a remote computer in order to work there, it's not a good idea to build remote execution into the command because you're just adding complication (e.g. many different ways to create sessions) and it's ultimately inefficient: you want the end user to create a single session and run multiple commands within it, rather than each command creating it's own session.
One thing I learned is that Invoke-Command cmdlet works on your local machine. I originally thought it only worked when running a command to a remote machine. I have one large function that houses a few other functions which work locally or remotely. If the ComputerName passed in is not the local host, I first verify if a PSSession is present and not in a broken state, and then create a new PSSession or utilize the existing session to run these functions persistently.
Hi,
I have been searching the web for any guidelines, examples or best practices for when you want to create functions within or not within a module that allows for local and remote execution, but I haven't found anything.
A good example is the Get-Service cmdlet. If you specify the ComputerName parameter, the cmdlet knows how to handle executing this the specified host. If the ComputerName parameter is not used, then the cmdlet executes on the local computer.
Any help or guidance is really appreciated.
Thanks,
Michael
The text was updated successfully, but these errors were encountered: