Creating World Map Graphs

by Jul 19, 2022

If you have data related to countries, you may want to visualize and highlight this geographic data. Classic bar- and chart-graphs won’t always work here.

Fortunately, there are free online geographic charts available that PowerShell can use. Here is a function you can try:

function Show-MapGraph


        $Label = 'Items'

        $bucket = [System.Collections.ArrayList]::new()
        $null = $bucket.Add($_)
        $groups = $bucket | Where-Object { $_.$Property } | Group-Object -Property $Property -NoElement 
        $data = foreach ($group in $groups)
            "['{0}',{1}]" -f $group.Name, $group.Count

        $datastring = $data -join "`r`n,"

        $HTMLPage = @"
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
      google.charts.load('current', {

      function drawRegionsMap() {
        var data = google.visualization.arrayToDataTable([
          ['Country', '$Label'],

        var options = {
          colorAxis: {colors: ['#00FF00', '#004400']},
          backgroundColor: '#81d4fa',
          datalessRegionColor: '#AAAABB',
          defaultColor: '#f5f5f5',

        var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));

        chart.draw(data, options);
    <div id="regions_div" style="width: 900px; height: 500px;"></div>
        $timestamp = Get-Date -Format 'HHmmss'
        $OutPath = "$env:tempGraph$timestamp.html"
        $HTMLPage | Out-File -FilePath $OutPath -Encoding utf8
        Start-Process $outpath

Show-MapGraph basically creates a HTML web page for you, fills it with the appropriate script calls, and then displays it. All you need to do is pipe in your country data, and use -Property to indicate which object property contains the country name.

Twitter This Tip! ReTweet this Tip!