0
votes

I have a CSV which i have processed subnet information in using CONCAT and some other functions. I have address range boundaries and Sites and want to automate the creation of SCCM IP Address Range boundaries using PowerShell and the CSV file and New-CMBoundary cmdlet. Please See below:

  • Column B is the Site Code
  • Column F Contains the Range e.g. 192.168.1.0-192.168.1.254

Code so far:

         'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin'
        Import-Module .\ConfigurationManager.psd1
        cd SCC:

                Get-CMSite

                $subnetranges = import-csv C:\subnets.csv
                $Site = $subnetranges | select -ExpandProperty "Site Code"
                $Range = $subnetranges | select -ExpandProperty "VLAN5 Range"

    ForEach ($subnet in $subnetranges) {

                    New-CMBoundary -DisplayName $Site -BoundaryType IPRange -Value $Range

    }

This obviously isn't quite right, Can you see what I'm trying to do? how do i get each row from the CSV into the respective variable but then enumerate through using the ForEach loop? If that is even the best method.

Thanks in Advance

2

2 Answers

0
votes

You can, according to this site and chap, pipe the values from a CSV to the NEW-CMBOUNDARY cmdlet.

http://www.dexterposh.com/2014/07/powershell-sccm-2012-boundaries.html

This is the actual video of the working code being ran: https://youtu.be/jjjigfddkm8

Essentially he just pipes the import-csv c:\file.csv | new-cmboundary with 3 values, Name, Type,Value and it works. I've copied this to the T and cannot for love nor money get this to work.Looking at the help for that cmdlet, pipeline input is not accepted. How did he get the pipeline input accepted?

0
votes

This is the answer:

#import boundaries
$csv = Import-Csv C:\iprangescsvnew.csv
cd POS:
foreach($line in $csv){

            Write-host "Creating boundary for $($line.subnet)"
            New-CMBoundary -Name $line.'Name' -Type IPRange -Value $line.Value }