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
}