[英]PowerShell: append string to result of Get-ADUser query
I want to attach a string to a Get-ADUser object.我想将字符串附加到 Get-ADUser 对象。
$VALUE = "Something : Else "
$RESULT = Get-ADUser -Filter 'givenName -eq "Joe" ' -Property * |
Select-Object -Property givenName, Surname, "$VALUE"
I got some bracket { } instead of "Else"我得到了一些括号 {} 而不是“Else”
PS C:\> $RESULT
givenName : Joe
Surname : Black
Something : Else : {}
But I want this here!但我想要这里!
PS C:\> $RESULT
givenName : Joe
Surname : Black
Something : Else
I try to put the Get-ADUser object into a string array and then attach $VALUE but that doesn't works.我尝试将 Get-ADUser 对象放入字符串数组,然后附加 $VALUE 但这不起作用。
Has anybody a idea?有人有想法吗?
Because I have to save it into a CSV file.因为我必须将它保存到一个 CSV 文件中。
$RESULT | Export-CSV $DESTINATION -NoTypeInformation -Encoding UTF8 -Delimiter ';'
The syntax for calculated properties uses hashtables with a Name
/ Label
and Expression
key (which you can shorten to n
and e
). 计算属性的语法使用带有Name
/ Label
和Expression
键(您可以缩短为n
和e
)的哈希表。
Name
must be a string (the name of your custom property), and Expression
must be a scriptblock. Name
必须是一个字符串(您的自定义属性的名称),并且Expression
必须是一个脚本块。
# long version
Select-Object -Property GivenName, Surname, @{Name = "Something"; Expression = {"Else"}}
# short version
select GivenName, Surname, @{n="Something";e={"Else"}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.