Basic Powershell
Variable
$<name>=<value>
$usrname='John'
$len=32
$null -> null value
$true -> boolean true
$false -> boolean false
$_ -> the variable currently being processed
Data Structure
Array
$var=@(<element>,<element>,...)
$var[0]
$var[100]=2333
Hash Table
$var=@{<key>=<value>,...}
$var[<key>]
$var.key
Process Control
Branch
if()
{
...
}
elseif()
{
...
}
else
{
...
}
switch($x)
{
condition {...;break}
default {...}
}
-gt greater than
-lt less than
-eq equal
Circulation
for(;;)
{
...
}
foreach($var in $set)
{
...
}
while()
{
...
}
do
{
...
}
while/until()
.NET & Class
Class
#show all members of a object
$var | gm
#call member function
$var.fun()
#visit member variable
$var.var
.NET
some methods to creat a new object
$obj = New-Object System.Version
$obj
$obj = New-Object System.Version 3 6
$obj
$obj = [System.Version]::New()
$obj
$obj = [System.Version]::New(3,6)
$obj
type conversion
$obj.ToString()
[int]1.7
[System.Version]'3.6.0.0'
Create a Class
class MyClass
{
<hidden|static>
[typename]$<member>
MyClass()#Constructor
{
...
}
}