即使条件返回false,If语句始终运行后的代码?

时间:2014-07-23 12:15:18

标签: powershell powershell-v3.0

我有一个If语句查看Test-Path命令的结果。 If语句之后的代码似乎总是运行,但是,即使test-Path返回False(我已经通过将test-Path的结果传递给Write-Host命令来证明这一点)。我错过了什么?代码在这里:

If (Test-Path  "\\server\students\home\$user") { 
            $user = $_.uname 
            Set-ItemProperty -Path "\\server\students\home\$user" -Name Attributes -Value "Normal"
            $acl = Get-Acl "\\server\students\home\$user"
            $acl.access | where-object {$_.AccessControlType -eq "Deny"} | Foreach-object { $acl.RemoveAccessRule($_) }
            (Get-Item "\\server\students\home\$user").SetAccessControl($acl)
            Get-ChildItem -Path "\\swcportal\students\home\$user\*" -Recurse | Remove-Item -Force -Recurse
            Remove-Item "\\server\students\home\$user" -Recurse
            Write-host "$user's home directory deleted successfully"
            }

0 个答案:

没有答案