「PowerShell」if文で論理否定(-not) を使用するサンプル

書式
if -not(条件式)
条件式がtrueの場合にfalseになります。
条件式がfalseの場合にtrueになります。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
tt = 456
if (-not($tt -eq 456)){
Write-Host "true 22"
}else{
Write-Host "false 33"
}
if (-not($tt -eq 123)){
Write-Host "true 11"
}
tt = 456 if (-not($tt -eq 456)){ Write-Host "true 22" }else{ Write-Host "false 33" } if (-not($tt -eq 123)){ Write-Host "true 11" }
tt = 456

if (-not($tt -eq 456)){ 
      Write-Host "true 22"
}else{
    Write-Host "false 33"  
}

if (-not($tt -eq 123)){ 
      Write-Host "true 11"  
}

実行結果
PS C:\study\powershell> .\test.ps1
false 33
true 11

PowerShell

Posted by arkgame