Powertip of the day from powershell.com last week Summary (6)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.