Public/Invoke-MerakiNetworkProvisionClients.ps1

function Invoke-MerakiNetworkProvisionClients {
    <#
    .SYNOPSIS
    Provisions clients for a Meraki network using the Meraki Dashboard API.
 
    .DESCRIPTION
    The Invoke-MerakiNetworkProvisionClients function allows you to provision clients for a specified Meraki network by providing the authentication token, network ID, and a client configuration string.
 
    .PARAMETER AuthToken
    The authentication token (API key) required to access the Meraki Dashboard API.
 
    .PARAMETER NetworkId
    The ID of the Meraki network for which you want to provision clients.
 
    .PARAMETER ClientConfig
    A string containing the client configuration. The string should be in JSON format and should include the "clients" property, as well as the configuration for each client.
 
    .EXAMPLE
    $config = [PSCustomObject]@{
        clients = @(
            [PSCustomObject]@{
                mac = "00:11:22:33:44:55"
                name = "Client1"
                devicePolicy = "Allowed"
                policiesBySsid = @{
                    "0" = [PSCustomObject]@{
                        devicePolicy = "Group policy"
                        groupPolicyId = "123456"
                    }
                    "1" = [PSCustomObject]@{
                        devicePolicy = "Blocked"
                    }
                }
            }
            [PSCustomObject]@{
                mac = "66:77:88:99:AA:BB"
                name = "Client2"
                devicePolicy = "Per connection"
                policiesBySsid = @{
                    "0" = [PSCustomObject]@{
                        devicePolicy = "Normal"
                    }
                    "1" = [PSCustomObject]@{
                        devicePolicy = "Allowed"
                    }
                }
            }
        )
    }
 
    $config = $config | ConvertTo-Json -Compress
    Invoke-MerakiNetworkProvisionClients -AuthToken "your-api-token" -NetworkId "L_123456789012345678" -ClientConfig $config
 
    This example provisions two clients for the Meraki network with ID "L_123456789012345678". The first client has MAC address "00:11:22:33:44:55", display name "Client1", and is allowed on SSID 0 using group policy "123456", and blocked on SSID 1. The second client has MAC address "66:77:88:99:AA:BB", display name "Client2", and has per-connection policy on SSID 0 and allowed policy on SSID 1.
 
    .NOTES
    The function requires the "Invoke-RestMethod" cmdlet to be available.
 
    The function returns the response from the API if the provisioning is successful, otherwise, it displays an error message.
    #>


    [CmdletBinding()]
    param (
        [parameter(Mandatory=$true)]
        [string]$AuthToken,
        [parameter(Mandatory=$true)]
        [string]$NetworkId,
        [parameter(Mandatory=$true)]
        [string]$ClientConfig
    )
    try {
        $header = @{
            "X-Cisco-Meraki-API-Key" = $AuthToken
            "content-type" = "application/json; charset=utf-8"
        }

        $body = $ClientConfig

        $url = "https://api.meraki.com/api/v1/networks/$NetworkId/clients/provision"

        $response = Invoke-RestMethod -Method Post -Uri $url -headers $header -UserAgent "MerakiPowerShellModule/1.0.8 DocNougat" -Body $body
        return $response
    }
    catch {
        Write-Debug $_
        Throw $_
    }
}