Creating functions for local and remote execution

Welcome Forums General PowerShell Q&A Creating functions for local and remote execution

This topic contains 4 replies, has 3 voices, and was last updated by

6 months, 4 weeks ago.

  • Author
  • #105502

    Points: 45
    Rank: Member

    Hi everyone!

    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.

    Thanks in advance!

  • #105508

    Points: 527
    Helping Hand
    Rank: Major Contributor

    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.

    Setting up an Internal PowerShellGet Repository

    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.

  • #105509

    Points: 45
    Rank: Member

    Thanks, Rob. I completely understand what you are saying.

    I was looking more for understanding best practices for creating cmdlets that allow for local and remote execution. Example:

    Get-Service -Name blah -ComputerName SomewhereElse

    Get-Service -name blah

    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.

  • #105512

    Points: 43
    Rank: Member

    That has more to do with how you design your script/function/cmdlet. Use Get-Help and check out the following help topics:

    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!

  • #105614

    Points: 45
    Rank: Member

    Hey Matt,

    Thanks for the details. I went read through what you suggested over the weekend. It has a lot of great detail on many topics and I learned a lot.

    I also checked out POSH\Style&PraticeGuide and left a comment there. I hope someone gets back to me.

    Unfortunately, I didn't find any examples of implementing a cmdlet for local and remote execution. If you find any, can you add here?


The topic ‘Creating functions for local and remote execution’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort