#定义变量 $a=10 $b=4 #计算变量 $result=$a*$b $msg="保存文本" #输出变量 $result $msg 40 保存文本
PS C:\test> ${"I"like $}="mossfly"
PS C:\test> ${"I"like $}
PS C:\test> $item=Get-ChildItem . PS C:\test> $item Directory: C:\test Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 2011/11/23 17:25 ABC -a--- 2011/11/24 18:30 67580 a.html -a--- 2011/11/24 20:04 26384 a.txt -a--- 2011/11/24 20:26 12060 alias -a--- 2011/11/24 20:27 12060 alias.ps1 -a--- 2011/11/23 17:25 0 b.txt -a--- 2011/11/23 17:25 0 c.txt -a--- 2011/11/23 17:25 0 d.txt -a--- 2011/11/25 11:20 556 employee.xml -a--- 2011/11/24 17:37 7420 name.html -a--- 2011/11/28 15:30 63 ping.bat -a--- 2011/11/24 17:44 735892 Powershell_Cmdlets.html -a--- 2011/11/28 17:03 60 test.ps1 -a--- 2011/11/23 17:37 242 test.txt -a--- 2011/11/28 16:42 170 test.vbs PS C:\test> $result=3000*(1/12+0.0075) PS C:\test> $result 272.5
PS C:\test> $a=$b=$c=123 PS C:\test> $a 123 PS C:\test> $b 123 PS C:\test> $c 123
$Value1 = 10 $Value2 = 20 $Temp = $Value1 $Value1 = $Value2 $Value2 = $Temp
PS C:\test> $value1=10 PS C:\test> $value2=20 PS C:\test> $value1,$value2=$value2,$value1 PS C:\test> $value1 20 PS C:\test> $value2 10
PS C:\test> ls variable:
Name Value
---- -----
"I"like $ mossfly
$ cls
? True
^ cls
_
1 1
a 123
args {}
b 123
c 123
ConfirmPreference High
ConsoleFileName
DebugPreference SilentlyContinue
。。。
PS C:\test> ls variable:value* Name Value ---- ----- value1 20 value2 10
PS C:\test> Test-Path variable:value1 True PS C:\test> Test-Path variable:value2 True PS C:\test> Test-Path variable:valueUnkonw False
PS C:\test> Test-Path variable:value1 True PS C:\test> del variable:value1 PS C:\test> Test-Path variable:value1 False
PS C:\test> New-Variable num -Value 100 -Force -Option readonly PS C:\test> $num=101 Cannot overwrite variable num because it is read-only or constant. At line:1 char:5 + $num <<<< =101 + CategoryInfo : WriteError: (num:String) [], SessionStateUnauthorizedAccessException + FullyQualifiedErrorId : VariableNotWritable PS C:\test> del Variable:num Remove-Item : Cannot remove variable num because it is constant or read-only. If the variable is read-only, ration again specifying the Force option. At line:1 char:4 + del <<<< Variable:num + CategoryInfo : WriteError: (num:String) [Remove-Item], SessionStateUnauthorizedAccessExcepti + FullyQualifiedErrorId : VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveItemCommand
PS C:\test> del Variable:num -Force PS C:\test> $num=101 PS C:\test> $num 101
PS C:\test> new-variable num -Value "strong" -Option constant PS C:\test> $num="why? can not delete it." Cannot overwrite variable num because it is read-only or constant. At line:1 char:5 + $num <<<< ="why? can not delete it." + CategoryInfo : WriteError: (num:String) [], SessionStateUnauthorizedAccessException + FullyQualifiedErrorId : VariableNotWritable PS C:\test> del Variable:num -Force Remove-Item : Cannot remove variable num because it is constant or read-only. If the variable is read-only, ration again specifying the Force option. At line:1 char:4 + del <<<< Variable:num -Force + CategoryInfo : WriteError: (num:String) [Remove-Item], SessionStateUnauthorizedAccessExcepti + FullyQualifiedErrorId : VariableNotRemovable,Microsoft.PowerShell.Commands.RemoveItemCommand
PS C:\test> new-variable name -Value "me" -Description "This is my name"
PS C:\test> ls Variable:name | fl *
PSPath : Microsoft.PowerShell.CoreVariable::name
PSDrive : Variable
PSProvider : Microsoft.PowerShell.CoreVariable
PSIsContainer : False
Name : name
Description : This is my name
Value : me
Visibility : Public
Module :
ModuleName :
Options : None
Attributes : {}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有