我主要使用PowerShell来处理Active Directory和MS。
存在使用join报告MultiValue对象的示例,但是在脚本中使用这些行似乎很麻烦。我想要一个脚本,将报告所有的对象,并给出标准属性和检测多阀属性,并与连接字符“%”导出它们。
发布于 2016-03-04 07:26:42
您提到了AD和Exchange,但仍然没有明确说明您要查询的是什么,以及哪些是“标准”属性。我猜你可能指的是AD用户属性,但下面提供的是更通用的。
通过将属性放入数组并使用Select-Object,可以选择要从对象检索的属性(属性)列表。在本例中,do需要提前知道哪些属性将是多值的:
# Create an object with regular and multi-valued properties. In your
# case I guess this will come from a Get-*User cmdlet or similar.
$test = New-Object -TypeName PSOBject -Property @{"one"=1;"two"=2;"multi"=@("a","b")}
# Define the list of properties you want to return from this object.
# In this list we include a calculated column to pull the multi-valued
# data out and -join it with the '%' character
$properties = @('one','two',@{Label="multi";Expression={($_.multi) -join "%"}})
# Now we pipe our object through Select-Object to pull out those
# properties we want, including the calculated one:
$test | Select-Object $Properties
one two multi
--- --- -----
1 2 a%b 请注意,计算属性的名称(标签)可以是您想要的任何名称;我使用了与原始属性相同的名称。
编辑:以下代码适用于上面的$test对象,将其转换为一个新对象,其中多值字段是一个字符串,其中"%“连接了原始数组成员。请注意,这并不使用准备好的表达式来转换多属性;相反,它使用Select-Object中的-ExpandProperty开关来动态完成工作。
$ConvertedProperties = @{}
foreach($Property in ($test | Get-Member -MemberType Properties)){
$Value = (Select-Object -InputObject $test -ExpandProperty $Property.Name) -join "%"
$ConvertedProperties.($Property.Name) = $Value
}
$ConvertedObject = New-Object -TypeName PSOBject -Property $ConvertedProperties
$ConvertedObject | Export-Csv filename.csv -NoTypeInformationhttps://stackoverflow.com/questions/35784625
复制相似问题