Powerhsell:属性变量中的多个值 [英] Powerhsell : Multiple Value in properties Variable
问题描述
从带有复选框的原始表单中,我得到了一个具有某些属性的 csv 文件.我想通过 cmdlet get-Adusers 使用这些属性.如果我在 csv 中只有一个值但没有一些值,则脚本正在工作.
我的 CSV 文件格式如下:
<预>"PropertiesSelected";"FilterSelected""SN,EmailAddress,CN,SamAccountName";DC=myDomain,DC=COM"目前我不尝试使用 "filterSelected"
我认为问题在于 powershell
将 "SN,EmailAddress,CN,SamAccountName"
理解为单个值
我使用的命令是这样的:Import-Csv c:\TempPowerShell\CheckBoxResults.csv -delimiter ";"|
ForEach-Object {$FilterSelected=$_.FilterSelected$PropertiesSelected=$_.PropertiesSelectedGet-ADUser -Properties "$PropertiesSelected" -Filter * -SearchScope Subtree -SearchBase "DC=MyDomain,DC=COM" -Server MyServer:3268}
非常感谢您的帮助,我快疯了:)
问候朱利安
不能使用具有多个属性的字符串作为参数输入.
您可以通过将命令构造为字符串然后使用 invoke-expression 执行它来解决此问题:
$command="get-aduser -properties $PropertiesSelected -Filter * -SearchScope Subtree -SearchBase "DC=MyDomain,DC=COM" -Server MyServer:3268"调用表达式 $command
问候保罗
From a primal form with checkbox I get a csv file with some properties. I want to used these properties with cmdlet get-Adusers. The script is working if I only have only one value in the csv but not with some.
My CSV file is format like this :
"PropertiesSelected";"FilterSelected" "SN,EmailAddress,CN,SamAccountName"; "DC=myDomain,DC=COM"
For the moment I don't try to used "filterSelected"
I think the problem is that powershell
understand "SN,EmailAddress,CN,SamAccountName"
as a single value
The command I used is like that :
Import-Csv c:\TempPowerShell\CheckBoxResults.csv -delimiter ";" |
ForEach-Object {
$FilterSelected=$_.FilterSelected
$PropertiesSelected=$_.PropertiesSelected
Get-ADUser -Properties "$PropertiesSelected" -Filter * -SearchScope Subtree -SearchBase "DC=MyDomain,DC=COM" -Server MyServer:3268
}
Thanks a lot for your help, I'm going to be crazy :)
Regards Julien
You cant use a String with multiple properties as parameter input.
You can get around this by constructing your command as string and then executing it with invoke-expression:
$command="get-aduser -properties $PropertiesSelected -Filter * -SearchScope Subtree -SearchBase "DC=MyDomain,DC=COM" -Server MyServer:3268"
Invoke-expression $command
Regards Paul
这篇关于Powerhsell:属性变量中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!