RestrictionsStringType parameter length
Limiting string input length
Http://powershell.com/cs/blogs/tips/archive/2010/08/23/limiting-string-input-length.aspx
Function get-filename {
Param (
[Validatelength (1, 8)]
[String]
$ Filename
)
"Your filename {0} is {1} chars long"-F $ filename, $ filename. Length
}
Call exampleGet-FILENAME "win.txt"
Use regular expressions to verify input parameters
Validate input using regular expressions
Http://powershell.com/cs/blogs/tips/archive/2010/08/24/validate-input-using-regular-expressions.aspx
Function get-knowledgebasearticle {
Param (
[Validatepattern ('^ KB \ D {6} $')]
[String]
$ KB
)
"You entered Knowledgebase ID $ kb"
}
Call exampleGet-knowledgebasearticle-kb "kb123456"
UsePowershellView object types
Finding object types with powershell
Http://powershell.com/cs/blogs/tips/archive/2010/08/25/finding-object-types-with-powershell.aspx
'Hallo'. GetType (). fullname
(4). GetType (). fullname
(2.6). GetType (). fullname
(Get-date). GetType (). fullname
Result:
System. String
System. int32
System. Double
System. datetime
Conversion object type
Converting Object Types
Http://powershell.com/cs/blogs/tips/archive/2010/08/26/converting-object-types.aspx
[Datetime] '4. 5.2010'
To obtain the local date format, follow these steps:
[Datetime]: parse ('4. 5.2010 ')
Actually equivalent. NET FrameworkUnderDatetime. parst (string ).
Limit the number parameter range
Restrict input to numeric ranges
Http://powershell.com/cs/blogs/tips/archive/2010/08/27/restrict-input-to-numeric-ranges.aspx
Function set-cursorsize {
Param (
[Validaterange (1,100)]
[Int]
$ Percent
)
$ Host. UI. rawui. cursorsize = $ percent
}
PairIntType parameter to set a range limit.
Mainly through[Validatexxxx]
FromPowershell.com
2010JanuaryFrom the 16 th to the 20 thPowertip of the day