powershell基础脚本编写实例

powershell基础脚本编写实例_第1张图片
powershell基础脚本编写实例_第2张图片

//赋值$i
PS C:\Users\Administrator> $i = 1

PS C:\Users\Administrator> $i.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                   
-------- -------- ----                                     --------                                                                                   
True     True     Int32                                    System.ValueType 

//类型转换$i
PS C:\Users\Administrator> [int16]$i=1

PS C:\Users\Administrator> $i.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                   
-------- -------- ----                                     --------                                                                                   
True     True     Int16                                    System.ValueType                                                                           

powershell基础脚本编写实例_第3张图片

数组

创建数组

powershell基础脚本编写实例_第4张图片

创建空数组, -is判断类型

powershell基础脚本编写实例_第5张图片

在这里插入代码片PS C:\Users\Administrator> $arr1=1..10
PS C:\Users\Administrator> $arr1
1
2
3
4
5
6
7
8
9
10

流量控制

powershell基础脚本编写实例_第6张图片

powershell基础脚本编写实例_第7张图片
条件判断if while 分支判断switch 循环遍历 for foreach

创建ps1脚本文件
powershell基础脚本编写实例_第8张图片
运行hello.ps1脚本在这里插入图片描述

if else分支判断

powershell基础脚本编写实例_第9张图片
在这里插入图片描述

switch分支判断

powershell基础脚本编写实例_第10张图片
在这里插入图片描述
分支加入判断语句
powershell基础脚本编写实例_第11张图片

for循环遍历

powershell基础脚本编写实例_第12张图片

foreach循环遍历

powershell基础脚本编写实例_第13张图片

while条件判断

powershell基础脚本编写实例_第14张图片

你可能感兴趣的:(#,运维,powershell,数据结构,python,c#)