小编J. *_*ond的帖子

如何使用$ _.在一个herestring变量?

我似乎无法弄清楚如何在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)

variables powershell herestring

2
推荐指数
1
解决办法
284
查看次数

标签 统计

herestring ×1

powershell ×1

variables ×1