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

 
Participant
3 months, 2 weeks ago.

  • Author
    Posts
  • #105502

    Participant
    Points: 0
    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!
    -Michael

  • #105508

    Participant
    Points: 160
    Helping Hand
    Rank: Participant

    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.

    https://blogs.technet.microsoft.com/chadcox/2017/09/20/powershell-working-with-internal-repositories/

    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

    Participant
    Points: 0
    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

    Participant
    Points: 27
    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:
    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!

  • #105614

    Participant
    Points: 0
    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?

    Thanks,
    Michael

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