Import boundaries to SCCM with powershell

 
This is the second blog post in a series of two where the first one was about exporting boundaries from ConfigMgr to .CSV files and you can check out that post here: https://timmyit.com/2017/04/25/export-boundaries-from-sccm-with-powershell/

Now its time for us to import it to ConfigMgr and it’s very simple to do, all you need is the powershell script listed below (it’s also available over at technet for download https://gallery.technet.microsoft.com/Import-boundaries-from-46b9a894 )

What do we want to achieve?

We want to be able to import the boundaries we exported in to .CSV files from the https://timmyit.com/2017/04/25/export-boundaries-from-sccm-with-powershell/ guide and have them to show up in ConfigMgr. There’s no built in feature to export and import boundaries as of now in ConfigMgr so that’s why we turn to powershell to help us out with this process.

The Script

#    .NOTES
#    ===========================================================================
#     Created on:    4/10/2017 
#     Modified on:   4/21/2017 
#     Created by:    Timmy Andersson
#     Twitter:       @TimmyITdotcom
#     Blog:          www.timmyit.com
#    ===========================================================================
#    .DESCRIPTION
#        Import Subnet an IPRange Boundries to CSV files. This script needs to run on the siteserver to work. 
#        Specify source path with the parameter -SourcePath

[CmdletBinding(DefaultParameterSetName = 'SourcePath')]
param
(
[Parameter(Mandatory = $true,
Position = 1)]
$SourcePath
)
 
Begin{
$SiteCodeObjs = Get-WmiObject -Namespace "root\SMS" -Class SMS_ProviderLocation -ComputerName $env:COMPUTERNAME -ErrorAction Stop
    foreach ($SiteCodeObj in $SiteCodeObjs)
    {
        if ($SiteCodeObj.ProviderForLocalSite -eq $true)
            {
            $SiteCode = $SiteCodeObj.SiteCode
            }
    }
$SitePath = $SiteCode + ":"
Import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0, $Env:SMS_ADMIN_UI_PATH.Length - 5) + '\ConfigurationManager.psd1')
}
Process
{
    $Subnets = (Import-csv "$SourcePath\BoundariesIPSubnet.csv") 
    $IPRanges = (Import-csv "$SourcePath\BoundariesIPRange.csv" )
 
 
Set-Location $SitePath
            If ($Subnets -ne $null)
            {
                Foreach ($Subnet in $Subnets)
                    {
                     New-CMBoundary -Type IPSubnet -Value "$($Subnet.Value)" -Name "$($Subnet.Key)"
                    }
            }
 
        If ($IPRanges -ne $null)
            {
                Foreach ($IPRange in $IPRanges)
                    {
                     New-CMBoundary -Type IPRange -Value "$($IPRange.Value)" -Name "$($IPRange.Key)"
                    }
            }
}

Example

  •  Save the script and run it from your site server
  • Call the script and specify the parameter -SourcePath for where you saved the .csv files that was created with the Export-Boundaries.ps1 script
    • Import-Boundaries.ps1 -SourcePath C:\temp\boundaries
  • Once the script finished the boundaries should be imported to your ConfigMgr environment.

Remember that you still need to create boundary groups and link them to your boundaries once your done with the import.

Until next time, cheers !

You can find me over at

[twitter-follow screen_name=’Timmyitdotcom’]

6 comments

  1. C:tempImport-Boundaries.ps1 : A parameter cannot be found that matches parameter name ‘SourcePath’.
    At line:1 char:25
    + .Import-Boundaries.ps1 -SourcePath C:tempboundaries
    + ~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Import-Boundaries.ps1], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Import-Boundaries.ps1

    Getting this error. I haven

      1. Seems like WordPress have added html characters to many of my scripts on the site, currently working cleaning up all the scripts provided. I’ve just updated this one so copy the current script and try it out.

Leave a Reply