if ((Get-ChildItem "I:\temp").Length -ne 0) {
$locations = (Get-Item "I:\temp"), (Get-ChildItem "I:\temp" -Directory -Recurse) | % {
Get-ChildItem -File $_.FullName |
Select-String -List -Pattern '^\d{3}-?\d{2}-?\d{4}$' |
% Path
}
if ($locations) {
$locations | Out-File "I:\temp\SSN_FILES.txt"
} else {
Get-ChildItem "I:\temp" -Exclude "fullpath.txt", "SSN_FILES.txt" | Remove-Item
}
}
我需要确定$locations
是否为true。如果它是真的,它执行第一个操作,如果为false,则执行第二个操作。我遇到的问题是,我找不到一种方法来确定$locations
是否为真(等于匹配的正则表达式)或不。如何确定一个变量是否返回可比较的语句
'如果($地点)...'测试,看看它的'$ null'或为零,或等效的。您应该查看'-match'运算符(请参阅['Get-Help about_Comparison_Operators'](https://msdn.microsoft.com/zh-cn/powershell/reference/5.1/microsoft.powershell.core/)约/ about_comparison_operators))。 –
[相关](https://blogs.msdn.microsoft.com/powershell/2006/12/24/boolean-values-and-operators/)。 –