PowerShell Mapping Function

Today I want to show you a helpful function I use very often the last time. From time to time I need a function to translate or map a value. For example the Mapping of Azure Locations or the Office 365 License SKUs.

For This is made a function to store and translate the mapping.

The Script

# v1.0 - Init



Function GET-Location {
   
    Param (
        [string]$Name,
        [string]$Searchcoloumn,
        [string]$resultcoloumn
    )
    $data = @(
        [pscustomobject]@{LocationDisplay = 'North Europe'; LocationName = 'northeurope' }
        [pscustomobject]@{LocationDisplay = 'West Europe'; LocationName = 'westeurope' }
        [pscustomobject]@{LocationDisplay = 'East Asia'; LocationName = 'eastasia' }
        [pscustomobject]@{LocationDisplay = 'Central US'; LocationName = 'centralus' }
        [pscustomobject]@{LocationDisplay = 'Japan West'; LocationName = 'japanwest' }
        [pscustomobject]@{LocationDisplay = 'South India'; LocationName = 'southindia' }
        [pscustomobject]@{LocationDisplay = 'France Central'; LocationName = 'francecentral' }
        [pscustomobject]@{LocationDisplay = 'Germany North'; LocationName = 'germanynorth' }
        [pscustomobject]@{LocationDisplay = 'Sweden Central'; LocationName = 'swedencentral' }
    )
 
    $result = $data | Where-Object { $_.$Searchcoloumn -eq $Name } | select -Property $resultcoloumn
    try {
        return $result[0].$resultcoloumn
  
    }
    catch {
        return "Nothing found"

    }
 
}


Get-Location -Name "North Europe" -Searchcoloumn LocationDisplay -resultcoloumn LocationName

You can get the latest Script from the GitHub Repo Seidlm/PowerShell-Templates: PowerShell Template – Logging Function (github.com)

Michael Seidl, aka Techguy
au2mate, everything

Leave a Comment

Your email address will not be published.

*

%d bloggers like this: