Home

Powershell get 2 letter ISO code for country

%3CLINGO-SUB%20id%3D%22lingo-sub-145013%22%20slang%3D%22en-US%22%3EPowershell%20get%202%20letter%20ISO%20code%20for%20country%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-145013%22%20slang%3D%22en-US%22%3E%3CP%3EHallo%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ewhen%20I%20use%20this%20powershell%20code%3C%2FP%3E%0A%3CP%3E%24User%20%3D%20Get-AzureADUser%20-Filter%20%22userPrincipalName%20eq%20'Mail'%22%20%3C%2FP%3E%0A%3CP%3E%24User.country%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20get%20as%20Output%20%22GERMAY%22.%20How%20I%20have%20to%20change%20the%20code%20to%20get%20%22DE%22%20%20(2%20letter%20ISO%20code)%20as%20output.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%3C%2FP%3E%0A%3CP%3EStefan%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-145013%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20AD%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-145956%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20get%202%20letter%20ISO%20code%20for%20country%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-145956%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20abbreviated%20ones%20represent%20the%20%22c%22%20attribute%2C%20but%20if%20I%20remember%20correctly%20that%20one%20is%20never%20surfaced%20in%20AAD%2FGraph.%20Instead%2C%20you%20can%20simply%20make%20your%20own%20mapping%20in%20accordance%20to%20ISO%203166-2%20(%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FISO_3166-2%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fen.wikipedia.org%2Fwiki%2FISO_3166-2%3C%2FA%3E)%20or%20just%20%22borrow%22%20some%20of%20the%20code%20samples%20available%20online%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

Hallo,

 

when I use this powershell code

$User = Get-AzureADUser -Filter "userPrincipalName eq 'Mail'"

$User.country

 

I get as Output "GERMAY". How I have to change the code to get "DE" (2 letter ISO code) as output.

 

Thanks

Stefan

1 Reply

The abbreviated ones represent the "c" attribute, but if I remember correctly that one is never surfaced in AAD/Graph. Instead, you can simply make your own mapping in accordance to ISO 3166-2 (https://en.wikipedia.org/wiki/ISO_3166-2) or just "borrow" some of the code samples available online :)

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
ChirmyRam in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies