打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
PowerShell脚本学习(二)
userphoto

2022.06.09 广东

关注

对变量的操作

1.1 变量操作

1.1.1 定义变量- $x方式(推荐)

        $a = 1

        $str = "hello world"

1.1.2 定义变量- Set-Variable

        Set-Variable a 1

        Set-Variable str "hello world"

1.1.3 查看变量

        # (查看所有变量)

            Get-Variable

        # 查看变量a

            Get-Variable a

        # 查看变量str

            Get-Variable str

        # 查看变量是以s开头的,不区分大小写

            Get-Variable s*

1.1.4 清空变量

        # 清空变量a

            Clear-Variable a

        # 清空多个变量,与查看变量一样的操作

            Clear-Variable str*

            这只是对变量的值进行清空,变量实际是还存在的

1.1.5 删除变量

        # 删除变量a

            Remove-Variable a

        # 删除多个变量,与前面清空、查询是一样的操作

            Remove-Variable str*

1.1.6 计算变量

        四则运算、赋值运算、比较运算、逻辑运算都满足

            $interget1=1

            $interget2=2

    # 加、减、乘、除、模

            $interget3=$interget1(+|-|*|/|%   =|+=|-=|*=|/=|%=   !|not|and|or)$interget2

    # 字符串操作

        $str="hello"

        $str1="world"

    # 输出,查看结果

        Write-Host ($str+$str1)

1.1.7 常量

    Set-Variable -Name conpany -Value "重庆城银科技" -Option Constant

    # 尝试改变变量值,其实这里会异常的

        $conpany="重庆中联信息"

    注意:常量不能使用$的方式进行声明,只能使用Set-Variable定义。

1.1.7 变量不同类型自带API的使用

            $date=Get-Date

        # 打印日期部分

            Write-Host $date.Date

        # 变量增加一天

            Write-Host ($date.AddDays(1))

        # 字符串截取

            $str.Substring(0,5)

        基本上常见的一些操作在Powershell中都支持

原文链接:https://blog.csdn.net/xhl_james/article/details/113697745 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Windows PowerShell基本语法及常用命令
BAT语句:if语句和for语句
Tkinter教程之Radiobutton篇
批处理if/else语句
十年经验总结——收藏吧,总有一天你用的上
MySQL存储过程详解
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服