日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

PowerTip of the Day from powershell.com上周汇总(六)

發(fā)布時(shí)間:2023/12/4 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PowerTip of the Day from powershell.com上周汇总(六) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

限制String類型參數(shù)的長(zhǎng)度

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
}

調(diào)用示例Get-FileName "win.txt"

?

?

用正則驗(yàn)證輸入的參數(shù)

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"
}

調(diào)用示例Get-KnowledgeBaseArticle -KB "KB123456"

?

?

Powershell查看對(duì)象類型

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

結(jié)果:

System.String

System.Int32

System.Double

System.DateTime

?

?

轉(zhuǎn)換對(duì)象類型

Converting Object Types

http://powershell.com/cs/blogs/tips/archive/2010/08/26/converting-object-types.aspx

[DateTime] '4.5.2010'

以下是獲取本地日期格式的方法:

[DateTime]::Parse('4.5.2010')

實(shí)際上相當(dāng)于.net framework下的DateTime.Parst(string).

?

?

限制數(shù)字參數(shù)范圍

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
}

對(duì)int型的參數(shù)做一個(gè)范圍限制。

主要通過[ValidateXXXX]

?

?

?

?

?

以上來(lái)自powershell.com

2010年八月份16日到20日的PowerTip of the Day

?

總結(jié)

以上是生活随笔為你收集整理的PowerTip of the Day from powershell.com上周汇总(六)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。