none
How can I avoid path when referencing script name in help? RRS feed

  • Question

  • When I create help for my PowerShell scripts, PowerShell always adds the script's path to the text. This looks extraordinarily awful.

    Is it possible to keep PowerShell from adding the (well known) path?


    Here's an example result, when output:

    PS D:\Documents\Visual Studio-Projekte\Visual Studio 2010\Projects\My Solution\My Project\SQL Scripts> help .\Run.ps1
    
    NAME
        D:\Documents\Visual Studio-Projekte\Visual Studio 2010\Projects\My Solution\My Project\SQL Scripts\Run.ps1
    
    ÜBERSICHT
        Führt alle SQL-Skripte im angegebenen Unterordner aus.
    
    
    SYNTAX
        D:\Documents\Visual Studio-Projekte\Visual Studio 2010\Projects\My Solution\My Project\SQL Scripts\Run.ps1 [[
        -RootPath] <String>] [[-Server] <String>] [[-UserName] <String>] [[-Password] <String>] [<CommonParameters>]
    
    
    BESCHREIBUNG
        Dieses Skript führt alle SQL-Skripte im angegebenen Unterordner aus. Wenn kein Unterordner angegeben ist, wird der
        aktuelle Ordner verwendet.
    
        Es werden all Unterordner rekursiv abgearbeitet.
    
        Die Reihenfolge, in der die SQL-Skripte verarbeitet werden, richtet sich nach den Dateinamen der SQL-Skripte.
    
        Wenn kein SQL-Server und keine Anmeldedaten angegeben werden, werden die SQL-Skripte standardmäßig in der lokalen
        Standard-SQL-Server-Instanz unter der aktuellen Windowsanmeldung ausgeführt.
    
        Geben Sie für eine Hilfe zu diesem Befehl "help .\Run.ps1" ein.
    
    
    VERWANDTE LINKS
    
    HINWEISE
        Zum Aufrufen der Beispiele geben Sie Folgendes ein: "get-help D:\Documents\Visual Studio-Projekte\Visual Studio 201
        0\Projects\My Solution\My Project\SQL Scripts\Run.ps1 -examples".
        Weitere Informationen erhalten Sie mit folgendem Befehl: "get-help D:\Documents\Visual Studio-Projekte\Visual Studi
        o 2010\Projects\My Solution\My Project\SQL Scripts\Run.ps1 -detailed".
        Technische Informationen erhalten Sie mit folgendem Befehl: "get-help D:\Documents\Visual Studio-Projekte\Visual St
        udio 2010\Projects\My Solution\My Project\SQL Scripts\Run.ps1 -full"

    Any help is appreciated.


    Vote here for a Microsoft Connect feedback channel on Windows - and win a better Windows!
    Vote here for a consistent keyboard shortcut support in Visual Studio and other Microsoft products!

    • Edited by BetterToday Wednesday, September 19, 2012 10:13 AM
    Wednesday, September 19, 2012 10:07 AM

Answers

  • You can also create a module, which works around this quite well.

    PoSH C:\scripts ► get-help Copy-ToPrinter
    
    NAME
        Copy-ToPrinter
    
    SYNOPSIS
        Copy-ToPrinter - Prints the current script from the ISE or a file passed the the Path parameter from the console.
    
    
    SYNTAX
        Copy-ToPrinter [[-Path] <String>] [<CommonParameters>]
    
    
    DESCRIPTION
        This script prints a PowerShell script.
    
    
    RELATED LINKS
    
    REMARKS
        To see the examples, type: "get-help Copy-ToPrinter -examples".
        For more information, type: "get-help Copy-ToPrinter -detailed".
        For technical information, type: "get-help Copy-ToPrinter -full".
    Karl

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    • Marked as answer by BetterToday Thursday, September 20, 2012 11:47 AM
    Wednesday, September 19, 2012 8:48 PM
  • Yes, you would need to register it, by running the script once (Assume you don't call the function in your script).  After that, if you dot-source it, your function will be available at the command line.

    To dot-source a function, do this (note the dot and the space after it) :

    . .\myfunction.ps1


    Grant Ward, a.k.a. Bigteddy

    • Marked as answer by BetterToday Thursday, September 20, 2012 11:47 AM
    Wednesday, September 19, 2012 4:49 PM

All replies

  • I don't think that is possible. Since you can't change the Name and Remarks properties and only append to most of the other properties. Check this link for some more information:

    http://blogs.msdn.com/b/powershell/archive/2009/05/28/adding-custom-cmdlet-help-for-providers.aspx

    Wednesday, September 19, 2012 10:33 AM
  • Make the script into an advanced function with comment-based help, and then call the function in the script (dot-source it).  Then if your user types:

    Help My-Function -Full

    ...there will be no path names, just the name of the function.


    Grant Ward, a.k.a. Bigteddy

    Wednesday, September 19, 2012 12:59 PM
  • I see... But is wrapping my code into a function(){} wrapper sufficient? Don't I need to register that function somehow?

    Given I'd name the function "Execute-Sql" and keep it in the Run.ps1 file, how would I call it from within PowerShell?

    Your help is very much apprecited!


    Vote here for a Microsoft Connect feedback channel on Windows - and win a better Windows!
    Vote here for a consistent keyboard shortcut support in Visual Studio and other Microsoft products!

    Wednesday, September 19, 2012 4:42 PM
  • Yes, you would need to register it, by running the script once (Assume you don't call the function in your script).  After that, if you dot-source it, your function will be available at the command line.

    To dot-source a function, do this (note the dot and the space after it) :

    . .\myfunction.ps1


    Grant Ward, a.k.a. Bigteddy

    • Marked as answer by BetterToday Thursday, September 20, 2012 11:47 AM
    Wednesday, September 19, 2012 4:49 PM
  • You can also create a module, which works around this quite well.

    PoSH C:\scripts ► get-help Copy-ToPrinter
    
    NAME
        Copy-ToPrinter
    
    SYNOPSIS
        Copy-ToPrinter - Prints the current script from the ISE or a file passed the the Path parameter from the console.
    
    
    SYNTAX
        Copy-ToPrinter [[-Path] <String>] [<CommonParameters>]
    
    
    DESCRIPTION
        This script prints a PowerShell script.
    
    
    RELATED LINKS
    
    REMARKS
        To see the examples, type: "get-help Copy-ToPrinter -examples".
        For more information, type: "get-help Copy-ToPrinter -detailed".
        For technical information, type: "get-help Copy-ToPrinter -full".
    Karl

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    • Marked as answer by BetterToday Thursday, September 20, 2012 11:47 AM
    Wednesday, September 19, 2012 8:48 PM