我以前使用过PowerShell,并了解它是如何工作的,但对格式的理解还不够,无法创建自己的脚本。
我正在尝试创建一个脚本,它将在某种意义上查询窗口,并根据响应,特定的操作将发生。如果否则是正确的呢?
这就是我想要做的:
运行命令get-computerRestorePoint将显示您已有的系统还原备份的输出。如果您没有配置系统还原,您将收到空输出。我应该从什么开始这个脚本?就像这样
If ($get-computerRestorepoint = null) {exit}
If ($get-computerRestorePoint = ) {run script.ps1}发布于 2015-06-10 03:05:31
PowerShell中的变量以$开头,就像$myVariable = 5一样。Cmdlet/函数是在没有修饰的情况下被调用的,所以你可以用Get-ComputerRestorePoint来调用它,没有$。
=用于赋值,但不用于测试等价性。
PowerShell使用类似于bash的运算符;它们以-开头
-eq (用于equals)-lt (用于小于than)-gt (用于大于)等。
null被指定为特殊变量名:$null
要执行脚本,可以使用与号&,因此编辑后的代码块将如下所示:
If (Get-ComputerRestorepoint -eq $null) {
exit
}
If (Get-ComputerRestorePoint) {
& script.ps1
}简而言之:
If (Get-ComputerRestorePoint) {
& script.ps1
} else {
exit
}实际上,如果在这个脚本的末尾,你可以省略else。
https://stackoverflow.com/questions/30740532
复制相似问题