请教一个问题:!$? 这个怎么理解?


PowerShell交流中心请教一个问题:!$? 这个怎么理解?
0
flyfree asked 5 年 ago

下面这个函数段里的(!$?) 指的是什么呢?怎么理解?

# Copy the exe file to the public’s desktop

If(Test-Path “$dirFiles\test.exe”) {
Copy-Item -Path “$dirFiles\test.exe” -Destination “$envCommonDesktop” -force -ErrorAction SilentlyContinue

If (!$?) {
$ErrorMessage = $error[0].Exception.Message
ExitOnError -ExitErrorCode 69016 -ErrorLogDetailedMessage “$ErrorMessage” -WriteToLog $true
} Else {
WriteToLog -message “$dirFiles\test.exe was copied successfully to $envCommonDesktop” -task $pendingtask -severity “info”
}

1 Answers
1
Best Answer
Mooser Lee 管理员 answered 5 年 ago

$? 代表的是上一条命令是否成功执行的结果,true代表执行成功,false代表执行失败。if( !$? ) { 执行失败的处理} 

flyfree replied 5 年 ago

多谢

he852100 replied 4 年 ago

!是-not的缩写