Adding Write Protection to functions

Functions by default have no write protection so they can easily be overwritten and redefined. You should do this if you'd like to make a function "read-only":

function ImportantFunction {
"You cannot overwrite me!"
}

(dir function:ImportantFunction).Options = 'ReadOnly'

Twitter This Tip! ReTweet this Tip!


Posted Dec 22 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.