古城热线 发表于 2018-9-2 12:28:03

8. PowerShell - 基础概要,变量,字符和字符串操作,运算符操作


[*]  PowerShell脚本的基础概要

[*]
[*]  常量,变量的使用
[*]  各种字符串的操作
[*]  对运算符的操作
[*]  数组,哈希表:创建、修改合并数组和哈希表
[*]  条件判断:if, switch 语句
[*]  逻辑判断:使用运算符进行判断
[*]  循环控制:while, do…while, do… until , for,foreach 语句
[*]  模块化:组织和调整代码;使用切当的数据类型,调用其它脚本函数
[*]  WMI对象:
  WMI命名空间的概念,WMI所提供的功能,查看和使用WMI命名空间。
  WMI的类:get-wmiobject;查询WMI
[*]  ADSI 对象
  Active Directory 对象的概念;
  ADSI所提供的功能;
  Active Directory命名空间;
  创建和修改ActiveDirectory对象

  参考:http://marui.blog.51cto.com/1034148/291383

[*]  PowerShell的变量
  

[*]  变量的赋值:
  $Str=“123”
  或set-variable-name Str –value “123”
[*]  声明变量时,回避一些“系统保留字”,如:
  Break | continue | do | else | elseif |filter | foreach | function | if | in | return | switch | until | where | while
[*]  输出变量
  Write-output $str
  或直接输入$str


[*]  PowerShell的字符和字符串
  
  1. 下面是PowerShell的常用数据类型说明:
  Hashtable:哈希表
  bool:true、false
  xml:xml对象
  array:数组
  decimal:十进制数,128bit
  byte:无符号字符,8bit
  char:unicode编码字符,16bit
  string:unicode编码字符串
  single:单精度32bit浮点
  double:双精度64bit浮点
  long:有符号,64bit
  int: 有符号,32bit
  $strA = “Hello “
  $strB = “World!”
  $strC = $strA + $strB
  $strC   结果:”Hello World!”
  字符串替换:
  $strA = “hi! world!”
  $strB = $strA -replace “hi!”, “Hello”
  $strB   结果:” hi!,World!”
  字符串引用:
  $strA = “ABC”
  "This is $strA.”    结果:” Thisis ABC”
  'This is $strA.'   结果:” This is $strA”

[*]  PowerShell的运算符操作(+,-,*,/,%,=,++,--)
  5 + 100
  $x=200+1
  $x
  $y=(7 + 13 * 2) / 10
  $y   结果:3
  参考:http://marui.blog.51cto.com/1034148/291383

页: [1]
查看完整版本: 8. PowerShell - 基础概要,变量,字符和字符串操作,运算符操作