PowerShell
- how to run script
[https://www.windowscentral.com/how-create-and-run-your-first-powershell-script-file-windows-10]
Set-ExecutionPolicy Restricted -- changed :A
若要了解计算机上的现用执行策略,请键入:
get-executionpolicy
若要在本地计算机上运行您编写的未签名脚本和来自其他用户的签名脚本,请使用以下命令将计算机上的
执行策略更改为 RemoteSigned:
set-executionpolicy remotesigned
- how to exe shell script
[https://cloud.tencent.com/developer/ask/60300]
一般来说,你调用一个本地命令,其路径中有一个空格,如下所示:
& "c:\some path with spaces\foo.exe" <arguments go here>
这是&后面跟着一个字符串,标识一个命令:cmdlet,函数,本机EXE相对或绝对路径。
一旦你得到这个:
& "c:\some path with spaces\foo.exe"
根据需要引用参数
- loop [https://www.pstips.net/powershell-for-loop.html]
$sum=0
$i=1
for(;$i -le 100;)
{
$sum+=$i
$i++
}
$sum
--arrays [http://www.splaybow.com/post/powershell-array.html]
初始化数组
$arr=1,2,3,'a','b','xx';
遍历数组
方法一:
foreach($a in $arr){$a}
foreach对于遍历一个集合(数组也算是一个集合)而言,真是太方便了。
方法二:
for($i=0;$i -lt $arr.Length; $i++){$arr[$i]}
这个就是普通的for循环,从C学到C++,再到Java或C#,一直都这么写,大家应该是比较熟悉的。
方法三:
$i=0; while($i -lt $arr.Length){$arr[$i];$i++}
- how to run script
[https://www.windowscentral.com/how-create-and-run-your-first-powershell-script-file-windows-10]
Set-ExecutionPolicy Restricted -- changed :A
若要了解计算机上的现用执行策略,请键入:
get-executionpolicy
若要在本地计算机上运行您编写的未签名脚本和来自其他用户的签名脚本,请使用以下命令将计算机上的
执行策略更改为 RemoteSigned:
set-executionpolicy remotesigned
- how to exe shell script
[https://cloud.tencent.com/developer/ask/60300]
一般来说,你调用一个本地命令,其路径中有一个空格,如下所示:
& "c:\some path with spaces\foo.exe" <arguments go here>
这是&后面跟着一个字符串,标识一个命令:cmdlet,函数,本机EXE相对或绝对路径。
一旦你得到这个:
& "c:\some path with spaces\foo.exe"
根据需要引用参数
- loop [https://www.pstips.net/powershell-for-loop.html]
$sum=0
$i=1
for(;$i -le 100;)
{
$sum+=$i
$i++
}
$sum
--arrays [http://www.splaybow.com/post/powershell-array.html]
初始化数组
$arr=1,2,3,'a','b','xx';
遍历数组
方法一:
foreach($a in $arr){$a}
foreach对于遍历一个集合(数组也算是一个集合)而言,真是太方便了。
方法二:
for($i=0;$i -lt $arr.Length; $i++){$arr[$i]}
这个就是普通的for循环,从C学到C++,再到Java或C#,一直都这么写,大家应该是比较熟悉的。
方法三:
$i=0; while($i -lt $arr.Length){$arr[$i];$i++}
没有评论:
发表评论