├── .gitattributes ├── README.md └── meraki_api_functions.ps1 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | These are a set of functions to interact with the Meraki cloud via the REST API. 2 | 3 | You will need to generate an API key on the Meraki Dashboard. 4 | 5 | You will need to collect some data to input some IDs in order for the functions to all work. 6 | 7 | 1. Input your API key in the $api_key variable where it says INSERT_API_KEY_HERE 8 | 2. Run the Get-MerakiOrganizations function... this will output the Organization ID (we will need this) 9 | 3. Under the Get-MerakiNetworks and Get-MerakiVPN functions place the Organization ID inside the $api.url variable where it says INSERT_ORGANIZATION_ID 10 | 4. Run the Get-MerakiNetworks... this will output your network(s) data (we will need the id from the networks that contain your switche(s), AP(s) and security appliance(s)) 11 | 5. Under the Get-MerakiSwitches, Get-MerakiAPs and Get-MerakiAppliances functions place the network ID (for the correct network: Get-MerakiSwitches will need the switch network ID,etc,etc) in the $api_url variable where it says INSERT_NETWORK_ID 12 | 13 | I accept tips if you found these functions useful: 14 | 15 | Bitcoin: 13E8u5PmKqrpvQRnBMPZjtFzo5nQr5SuuL -------------------------------------------------------------------------------- /meraki_api_functions.ps1: -------------------------------------------------------------------------------- 1 | #Insert your API key here 2 | 3 | $api_key = 'INSERT_API_KEY_HERE' 4 | 5 | 6 | function Get-MerakiSwitches { 7 | 8 | $header = @{ 9 | 10 | "X-Cisco-Meraki-API-Key" = $api_key 11 | "Content-Type" = 'application/json' 12 | 13 | } 14 | 15 | $api = @{ 16 | 17 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 18 | 19 | } 20 | 21 | $api.url = '/networks/INSERT_NETWORK_ID/devices' 22 | $uri = $api.endpoint + $api.url 23 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 24 | return $request 25 | 26 | } 27 | 28 | function Get-MerakiAPs { 29 | 30 | $api = @{ 31 | 32 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 33 | 34 | } 35 | 36 | $header = @{ 37 | 38 | "X-Cisco-Meraki-API-Key" = $api_key 39 | "Content-Type" = 'application/json' 40 | 41 | } 42 | 43 | $api.url = '/networks/INSERT_NETWORK_ID/devices' 44 | $uri = $api.endpoint + $api.url 45 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 46 | return $request 47 | 48 | } 49 | 50 | function Get-MerakiAppliances { 51 | 52 | $api = @{ 53 | 54 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 55 | 56 | } 57 | 58 | $header = @{ 59 | 60 | "X-Cisco-Meraki-API-Key" = $api_key 61 | "Content-Type" = 'application/json' 62 | 63 | } 64 | 65 | $api.url = '/networks/INSERT_NETWORK_ID/devices' 66 | $uri = $api.endpoint + $api.url 67 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 68 | return $request 69 | 70 | } 71 | 72 | function Get-MerakiVPN { 73 | 74 | $api = @{ 75 | 76 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 77 | 78 | } 79 | 80 | $header = @{ 81 | 82 | "X-Cisco-Meraki-API-Key" = $api_key 83 | "Content-Type" = 'application/json' 84 | 85 | } 86 | 87 | $api.url = '/organizations/INSERT_ORGANIZATION_ID/thirdPartyVPNPeers' 88 | $uri = $api.endpoint + $api.url 89 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 90 | return $request 91 | 92 | } 93 | 94 | function Get-MerakiNetworks { 95 | 96 | $api = @{ 97 | 98 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 99 | 100 | } 101 | 102 | $header = @{ 103 | 104 | "X-Cisco-Meraki-API-Key" = $api_key 105 | "Content-Type" = 'application/json' 106 | 107 | } 108 | 109 | $api.url = '/organizations/INSERT_ORGANIZATION_ID/networks' 110 | $uri = $api.endpoint + $api.url 111 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 112 | return $request 113 | 114 | } 115 | 116 | function Get-MerakiOrganizations { 117 | 118 | $api = @{ 119 | 120 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 121 | 122 | } 123 | 124 | $header = @{ 125 | 126 | "X-Cisco-Meraki-API-Key" = $api_key 127 | "Content-Type" = 'application/json' 128 | 129 | } 130 | 131 | $api.url = '/organizations' 132 | $uri = $api.endpoint + $api.url 133 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 134 | return $request 135 | 136 | } 137 | 138 | function Get-MerakiSwitchPorts { 139 | 140 | #Useage: Get-MerakiSwitchPorts "SW01" 141 | 142 | param ( 143 | 144 | [Parameter(Mandatory = $true)] 145 | [ValidateNotNullOrEmpty()] 146 | [String] 147 | $switch_name 148 | 149 | ) 150 | 151 | $switch = Get-MerakiSwitches | where {$_.name -eq $switch_name} 152 | 153 | if ($switch){ 154 | 155 | $api = @{ 156 | 157 | "endpoint" = 'https://dashboard.meraki.com/api/v0' 158 | 159 | } 160 | 161 | $header = @{ 162 | 163 | "X-Cisco-Meraki-API-Key" = $api_key 164 | "Content-Type" = 'application/json' 165 | 166 | } 167 | 168 | $api.url = "/devices/" + $switch.serial + "/switchPorts" 169 | $uri = $api.endpoint + $api.url 170 | $request = Invoke-RestMethod -Method GET -Uri $uri -Headers $header 171 | return $request 172 | 173 | } 174 | else{ 175 | 176 | Write-Host "Switch doesn't exist." -ForegroundColor Red 177 | 178 | } 179 | 180 | } --------------------------------------------------------------------------------