有没有一种更优雅的方式在PowerShell中编写以下if语句
[ValidateNotNull()]
[ValidateSet('Service', 'Role', 'RoleService', 'Feature', 'Group', 'File', 'Package')]
[Parameter(Mandatory = $true, Position = 1)]
[string[]]
$ProcessingModes
if ($ProcessingModes -contains 'Role' -or $ProcessingModes -contains 'RoleService' -or $ProcessingModes -contains 'Feature')
{
}
最佳答案
您可以很容易地执行数组交集:
$keyModes = 'Role', 'RoleService', 'Feature'
if ($keyModes | ? { $ProcessingModes -contains $_ }) { "found at least one" }
关于powershell - 在PowerShell中比较多个数组值的更优雅的方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23375688/