如何轻松地将输入国家/地区添加到输出csv文件中的每一行,以便如果我在国家/地区参数的多个国家/地区执行此操作,我会在每行上获取国家/地区信息?
param([string[]]$Country="Norway",[string]$file="ExUsersNO.csv")
Import-Module ActiveDirectory
foreach ($i in $Country)
{
Get-ADUser -searchbase "ou=$i,ou=FMS,dc=xx,dc=xx,dc=com" -Filter * -properties msExchVersion,name,mail,DistinguishedName,whenCreated |
Select-Object -Property name,mail,DistinguishedName,msExchVersion,whenCreated |
Sort-Object name |
Export-Csv -Path ".\$file" -Append -Encoding UTF8
}
答案 0 :(得分:2)
在您的select
声明中使用calculated property:
select name,mail,DistinguishedName,msExchVersion,whenCreated,@{Name='Country';Expression={$i}}