我似乎无法弄清楚如何在herestring中使用变量,以及稍后在管道命令中扩展变量.我尝试过单引号'和双"引号,以及转义`字符.
我试图将herestring用于Exchange组的列表(例如数组),以及应用于这些组的相应条件列表.这是一个简化的示例,它无法$Conditions正确使用变量(它不会扩展$_.customattribute2变量):
# List of groups and conditions (tab delimitered)
$records = @"
Group1 {$_.customattribute2 -Like '*Sales*'}
Group2 {$_.customattribute2 -Like '*Marketing*' -OR $_.customattribute2 -Eq 'CEO'}
"@
# Loop through each line in $records and find mailboxes that match $conditions
foreach ($record in $records -split "`n") {
($DGroup,$Conditions) = $record -split "`t"
$MailboxList = Get-Mailbox -ResultSize Unlimited
$MailboxList | where $Conditions
}
Run Code Online (Sandbox Code Playgroud)