[英]Powershell include variable in output csv
How can I easily add the input country to each line in the output csv file so that if I execute this with several countries for the country parameter I get the country info on each line? 如何在输入的csv文件中轻松地将输入国家/地区添加到每一行中,以便在对country参数使用多个国家/地区执行此操作时,可以在每一行中获取国家/地区信息?
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
}
将计算所得的属性与select
语句一起使用:
select name,mail,DistinguishedName,msExchVersion,whenCreated,@{Name='Country';Expression={$i}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.