Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/38a297d9ed7550510149474787285ecd to your computer and use it in GitHub Desktop.
Save gioxx/38a297d9ed7550510149474787285ecd to your computer and use it in GitHub Desktop.
Tiro fuori una lista di paesi dai quali accetto accesso condizionale (M365) in base al nome dato al gruppo località in AzureAD.
<#
OFFICE 365: Expand Countries from Location Policies on Azure AD (Get-AzureADMSNamedLocationPolicy) for PowerShell 7
---------------------------------------------------------------------------------------------------
Autore: GSolone
Versione: 0.1
Utilizzo: .\AzureADMSNamedLocationPolicy-CountriesTranslate.ps1
Info: https://gioxx.org/tag/o365-powershell
Fonti utilizzate: https://learn.microsoft.com/en-us/powershell/module/azuread/get-azureadmsnamedlocationpolicy?view=azureadps-2.0
https://datahub.io/core/country-list
https://stackoverflow.com/a/5466355/2220346
https://community.spiceworks.com/topic/1996389-extract-values-from-csv
https://kbase.io/check-if-azuread-connection-has-been-established-in-powershell/
Ultima modifica: 04-01-2023
Modifiche:
0.1- prima versione.
#>
Function LoadData($filename) {
try {
$data = Import-Csv $filename -Delimiter ","
} catch {
throw $_.Exception.Message
}
return $data
}
$AzureAdModule = Get-Module -Name AzureAd -ListAvailable
if ($AzureAdModule.count -eq 0) {
Write-Host "You must install AzureAd module to use this script. Copy and paste this command (then launch again this script): `nInstall-Module AzureAd" -f "Yellow"
Exit
}
else {
try {
$var = Get-AzureADTenantDetail
}
catch [Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthenticationException] {
Write-Host "You're not connected to AzureAD"
Import-Module AzureAd -UseWindowsPowershell
Connect-AzureAd | Out-Null
}
}
if (Get-Item -Path "$PSScriptRoot\countries.csv" -ErrorAction Ignore) {
$data = LoadData("$PSScriptRoot\countries.csv")
} else {
Invoke-WebRequest "https://datahub.io/core/country-list/r/data.csv" -OutFile "$PSScriptRoot\countries.csv"
$data = LoadData("$PSScriptRoot\countries.csv")
}
$countries = Get-AzureADMSNamedLocationPolicy | Where { $_.DisplayName -like "Località conosciute"} | Select-Object -ExpandProperty CountriesAndRegions | Sort
$countries | Foreach-Object {
Foreach ($country in $data) {
if ($country.Code -eq $_) { Write-Host $country.Name }
}
}
Remove-Item "$PSScriptRoot\countries.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment