我有一个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"
}