Forum Discussion

mikhailf's avatar
mikhailf
Iron Contributor
Jul 13, 2022
Solved

Create Named Location list using PowerShell

Hello Community,    I am trying to build a PowerShell script that will create a Named Location in Azure AD with multiple IP ranges. Here: New-AzureADMSNamedLocationPolicy (AzureAD) | Microsoft Doc...
  • LainRobertson's avatar
    LainRobertson
    Jul 13, 2022

    mikhailf 

     

    Here's a quick-n-dirty re-working if your original script demonstrating the Get-Content approach.

     

    I've included a screenshot showing the output from $ipRanges but I had to keep the subtle change regarding "`1", otherwise, it throws an error for me under Windows PowerShell.

     

    Connect-AzureAD
    $ipRanges = New-Object -TypeName System.Collections.Generic.List`1[Microsoft.Open.MSGraph.Model.IpRange]
    
    Get-Content -Path C:\IPs.csv |
        ForEach-Object {
            $ipRanges.Add($_)
        }
    
    New-AzureADMSNamedLocationPolicy -OdataType "#microsoft.graph.ipNamedLocation" -DisplayName "IP named location policy" -IsTrusted $false -IpRanges $ipRanges

     

    $ipRanges output (purely as confirmation it's correctly producing the IpRange data type):

     

    Cheers,

    Lain

Resources