PowerShell:ForEach-Object请求参数 [英] PowerShell: ForEach-Object asks for parameter
本文介绍了PowerShell:ForEach-Object请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个脚本片段,其中我的"ForEach-Object"部分要求参数。但我不知道它们应该在哪里。
I have a script snippet, in which my "ForEach-Object" part asks for parameters. But I don't know where they should be.
#### Check if MailContact is already in AD Group ####
$inG = 0;
(Get-DistributionGroupMember -Identity "$distGroup" -ErrorAction SilentlyContinue) | ForEach-Object
{
if($_.name -match $name)
{
$inG = 1; #Name found, so contact in Group
"$name already in $distGroup, search complete!";
break; #Break from ForEachObject
} else {
$inG = 0; #Not found, continue with loop
}
}
if($inG -eq 0)
{
#Not in group at all, add
"Adding $name to $distGroup";
Add-DistributionGroupMember -Identity "$distGroup" -Member "$name";
}
控制台输出如下:
<emailremoved> ist bereits als Kontakt vorhanden #<-- comes from a part not in the snippet
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
Process[0]:
祝你好运,
Phillip
推荐答案
这是你的foreach-object,卷曲括号必须与foreach-object位于同一行。
It's your foreach-object, the curly bracket has to be on the same line as the foreach-object.
### OLD
inG = 0;
(Get-DistributionGroupMember -Identity"
inG = 0; (Get-DistributionGroupMember -Identity "
distGroup" -ErrorAction SilentlyContinue)| ForEach-Object
{
### NEW
distGroup" -ErrorAction SilentlyContinue) | ForEach-Object { ### NEW
这篇关于PowerShell:ForEach-Object请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文