Override build-in cmdlets in Powershell

This topic contains 1 reply, has 2 voices, and was last updated by  Dave Wyatt 1 year, 10 months ago.

  • Author
    Posts
  • #32809

    GS
    Participant

    Hello,

    Is it possible to override build in cmdlets in Powershell with my own ones. Like for example I want to have a common library which will be dot sourced and I will specify my own Send-Mail function there which will provide generic services for all my scripts with defaults I want. I understand I can write my own function with my own name but I already have tons of scripts relying on Send-Mail cmdlet and would like to override if it's possible with utility script I will to all my scripts instead.

  • #32813

    Dave Wyatt
    Moderator

    Yep. If you define a function with the same name as a cmdlet, the function will be resolved first, as detailed in the about_Command_Precedence help file (https://technet.microsoft.com/en-us/library/hh848304.aspx). This is what allows proxy functions and other such tricks to work.

You must be logged in to reply to this topic.