Я бы предложил использовать switch
, Export-Csv
и вычисленные свойства с Select-Object
:
$UserList | Select-Object -Property @(
'SamAccountName', 'Enabled', 'GivenName', 'Surname'
'Title'
'Mail'
'LastLogonDate'
'Department', 'Office'
'OfficePhone', 'MobilePhone'
'WhenCreated', 'WhenChanged'
@{
Label = 'AccountExpires'
Expression = {
if ($PSItem.accountExpires -eq 1) {
$PSItem.AccountExpirationDate
} else {
'N/A'
}
}
}
@{
Label = 'Country'
Expression = {
switch ($PSItem) {
{$PSItem.Country -eq 'CA' -or $PSItem.DistinguishedName -eq 'CANADA'} {
'Canada'
}
{$PSItem.Country -eq 'LUX' -or $PSItem.DistinguishedName -eq 'LUXEMBOURG'} {
'Luxembourg'
}
{$PSItem.Country -eq 'BRL' -or $PSItem.DistinguishedName -eq 'BRAZIL'} {
'Brazil'
}
{$PSItem.Country -eq 'USA' -or $PSItem.DistinguishedName -eq 'US'} {
'America'
}
{$PSItem.Country -eq 'UNITED KINGDOM' -or $PSItem.DistinguishedName -eq 'GB'} {
'United Kingdom'
}
{$PSItem.Country -eq 'HONG KONG' -or $PSItem.DistinguishedName -eq 'HK'} {
'Hong Kong'
}
{$PSItem.Country -eq 'INDIA' -or $PSItem.DistinguishedName -eq 'IN'} {
'India'
}
{$PSItem.Country -eq 'AUSTRALIA' -or $PSItem.DistinguishedName -eq 'AU'} {
'Australia'
}
}
}
}
) | Export-Csv -Path C:\Temp\UserList.csv -NoTypeInformation -Force -Encoding UTF8