PowerShell has a comparison operator called –is. The –is operator simply response
True or False when you use it to verify the data type of a value.
The valid data types in PowerShell are:
[string] Fixed-length string of Unicode characters
[char] A Unicode 16-bit character
[byte] An 8-bit unsigned character
[int] 32-bit signed integer
[long] 64-bit signed integer
[bool] Boolean True/False value
[decimal] A 128-bit decimal value
[single] Single-precision 32-bit floating point number
[double] Double-precision 64-bit floating point number
[DateTime] Date and Time
[xml] Xml object
[array] An array of values
[hashtable] Hashtable object
Below is a script that will use –is to test some values.
[string] Fixed-length string of Unicode characters
[char] A Unicode 16-bit character
[byte] An 8-bit unsigned character
[int] 32-bit signed integer
[long] 64-bit signed integer
[bool] Boolean True/False value
[decimal] A 128-bit decimal value
[single] Single-precision 32-bit floating point number
[double] Double-precision 64-bit floating point number
[DateTime] Date and Time
[xml] Xml object
[array] An array of values
[hashtable] Hashtable object
Below is a script that will use –is to test some values.
$String = "Hello" $Boolean = $True $Int = 15
Write-Host "Test for
string"
$String -is [String]
$Boolean -is [String]
$Int -is [String]
|
Test for string
True
False
False
|
Write-Host "Test
for Boolean"
$String -is [Boolean]
$Boolean -is [Boolean]
$Int -is [Boolean]
|
Test for Boolean
False
True
False
|
Write-Host "Test for
Integer"
$String -is [Int32]
$Boolean -is [Int32]
$Int -is [Int32]
|
Test for Integeк
False
False
True
|
No comments:
Post a Comment