Sign in
Monad
Monad Technology Blog
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
Atom
RSS for comments
Search
Tags
No tags have been created or used yet.
Archive
Archives
April 2006
(10)
March 2006
(7)
February 2006
(8)
January 2006
(7)
December 2005
(6)
November 2005
(8)
October 2005
(2)
September 2005
(5)
August 2005
(7)
Did you know? #3
MSDN Blogs
>
Monad
>
Did you know? #3
Did you know? #3
arulk
25 Aug 2005 11:41 PM
Comments
3
Did you know that you can put constraints on variables using the same
attributes as cmdlet parameters?
Unfortunately we had to postpone the language support for this but you can
still do it using new-object.
MSH > $a = "foo"
MSH > $varA = get-variable a
MSH > $varA
Name Value
---- -----
a foo
MSH > $varA.Attributes.Add($(new-object
System.Management.Automation.ValidateLengthAttribute -arg 1,10))
MSH > $a = ""
: Cannot validate because of invalid value () for variable a.
At line:1 char:3
+ $a <<<< = ""
MSH > $a = "somethingreallylong"
: Cannot validate because of invalid value (somethingreallylong) for
variable
a.
At line:1 char:3
+ $a <<<< = "somethingreallylong"
MSH > $a = "just right"
MSH > $a
just right
-Jeff Jones
3 Comments
Blog - Comment List MSDN TechNet
Comments
Loading...
Leave a Comment
Name
Comment
Please add 5 and 7 and type the answer here:
Post