Adding Protection to Functions

by Apr 5, 2010

Functions that you define are read/write and can easily be overwritten. You can set the read-only attribute to make a function read-only so that you get a warning if you try to overwrite it. This line sets the read-only attribute for a function named "test" (which must exist):

Set-Item Function:test -Option ReadOnly

Twitter This Tip! ReTweet this Tip!