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?
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}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.