这可能是一个新手问题,但我现在已经花了几个小时。我正在创建一个 powershell 脚本,试图确定一个条目是否已经存在。(这适用于 Exchange 多租户解决方案)这有效:
Get-GlobalAddressList | Where{$_.Identity -Like "\MyCompany_com*"}
但这失败了:
Get-GlobalAddressList | Where{$_.Identity -Like "\MyCompany_com - GAL"}
出于某种原因,我无法理解,条目中的空格不匹配。
是的,我确定该条目\MyCompany_com - GAL
存在。我已经尝试了所有我能想到的组合使用 -match、-eq、-contains 任何帮助表示赞赏!
- - 编辑 - - - - - - - - - - -
尝试了一种新的技巧,仍然惨败:
$NewVal = "\MyCompany_com - GAL"
$Prop = Get-GlobalAddressList | Select Name
foreach($PropVal in $Prop.Name){
write-output "comparing: $NewVal to $PropVal"
if($NewVal -like $PropVal){write-output "MATCH"} else {write-output "no-match"}
}
写入输出“显示”字符匹配字符。
3 多年来,我使用多种语言编写脚本,但这个 PowerShell 废话让我感到困惑。#沮丧的#
---- 编辑#2(显示输出)----------
comparing: MyCompany_com - GAL to MyCustomer_com - GAL
no-match
comparing: MyCompany_com - GAL to MyCompany_com - GAL
no-match
comparing: MyCompany_com - GAL to Default Global Address List
no-match
有什么方法可以强制进行字符串比较?
空格字符还在困扰我吗?
---- 编辑#3(仍在尝试)----------
我创建了一个新的 GlobalAddressList:"MCC-GAL"
故意没有空格。
这仍然不起作用:
Get-GlobalAddressList | Where{$_.Name -Like "MCC-GAL"}
但是,这确实匹配:
Get-GlobalAddressList | Where{$_.Name -Like "MCC?GAL"}
因此,除了空格字符之外,连字符 (-) 也会导致匹配问题。我确实尝试过转义连字符:“\-”,但仍然不匹配。
有没有办法强制进行简单的字符串比较?我用来构建比较字符串的方法将是我需要匹配的。