What is a wrapper ?

Welcome Forums General PowerShell Q&A What is a wrapper ?

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

11 months, 3 weeks ago.

  • Author
  • #95115

    Points: 1
    Rank: Member

    What is a wrapper ?

    In section 3.3. Asking for help of "Learn PowerShell in 30 Days of Lunches" it states:

    "Man and Help aren't native cmdlets at all; they're functions, which are wrappers around the core Get-Help cmdlet."

    I've seen the terminology "wrapper" before. I've searched online for a definition, but as of yet have never found one that makes any sense (at least to me). I'm not even sure if the usage of the term wrapper here is the same as the programmatic definition of wrapper – and it seems there are multiple definitions of wrapper ?

    So a wrapper is a function. It made creating PowerShell eaiser. It makes working with PowerShell easier. As far as I can tell both are passing user input to Get-Help ?

  • #95122

    Points: 780
    Helping Hand
    Rank: Major Contributor

    There are wrappers (as you note, functions they focus normally on a specific thing) and then there are aliases (shorthand stuff).

    Making a PowerShell Command Your Own

    Wrapper Functions

    By contrast, a wrapper function typically focuses on a single cmdlet, but it can be customized to meet a specific need. For example, you might want to adjust parameters, or you might want to further process the results. Many of the tools you will build will most likely rely on wrapper functions.

    Any function, can be assigned an alias.

    When digging as aliases, PoSH give you this list natively. Aliases are just short name to the normal cmdlet. They are good for quickly do interactive sessions. Though they are not prudent for full blown scripts. Never assume that those you share scripts with, will ever know anything about aliases. If it is just you. Alias away. If you share, use the full cmdlet names.

        # Get parameters, examples, full and Online help for a cmdlet or function
        (Get-Command -Name Get-Content).Parameters
        Get-help -Name Get-Content -Examples
        Get-help -Name Get-Content -Full
        Get-help -Name Get-Content -Online
        Get-Help about_*
        Get-Help about_Functions
        # Find all cmdlets / functions with a target parameter
        Get-Help * -Parameter Append
        # All Help topics locations
        explorer "$pshome\$($Host.CurrentCulture.Name)"
        Get-Alias | Out-GridView -PassThru
        Get-Alias -Definition '*Help*' | Format-Table -AutoSize
        CommandType Name        Version Source
        ----------- ----        ------- ------
        Alias       man -> help   
        Get-Alias -Definition 'Get-WmiObject' | Format-Table -AutoSize
        CommandType Name                  Version Source
        ----------- ----                  ------- ------
        Alias       gwmi -> Get-WmiObject               
        Get-Alias -Definition 'Get-ChildItem' | Format-Table -AutoSize
        CommandType Name                 Version Source
        ----------- ----                 ------- ------
        Alias       dir -> Get-ChildItem               
        Alias       gci -> Get-ChildItem               
        Alias       ls -> Get-ChildItem   
        Get-Command -Type Function
        Get-Command -Type Cmdlet
  • #95131

    Points: 0
    Rank: Member

    There's a reasonable generic definition of wrapper functions at https://en.wikipedia.org/wiki/Wrapper_function

    Think of them as a way to access functionality in an easier manner. As a simple example I have a function in my PowerShell profile

    function doc {
    param (
    Get-Help -Name $subject -ShowWindow

    doc get-Command

    is equivalent to
    Get-Help -Name Get-Command -ShowWindow

    It saves me some time and some typing

    doc is a wrapper function for get-help

The topic ‘What is a wrapper ?’ is closed to new replies.

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