-
Notifications
You must be signed in to change notification settings - Fork 9
/
Example.ps1
41 lines (31 loc) · 1.08 KB
/
Example.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# From an elevated PowerShell prompt:
# Install-Package Meraki.Api -ProviderName NuGet
# ./Example.ps1
Import-Module Microsoft.Extensions.Logging
Import-Module Microsoft.Extensions.Logging.Console
Import-Module Meraki.Api
function Wait-Task {
param(
[Parameter(Mandatory, ValueFromPipeline)]
[System.Threading.Tasks.Task[]]$Task
)
Begin {
$Tasks = @()
}
Process {
$Tasks += $Task
}
End {
While (-not [System.Threading.Tasks.Task]::WaitAll($Tasks, 200)) {}
$Tasks.ForEach( { $_.GetAwaiter().GetResult() })
}
}
Set-Alias -Name await -Value Wait-Task -Force
$factory = [Microsoft.Extensions.Logging.LoggerFactory]::Create({
param($builder)
$builder.AddConsole()
})
$logger = $factory.CreateLogger('MyLogger')
$Options = New-Object Meraki.Api.MerakiClientOptions -Property @{ApiKey="XXX"; UserAgent = "MyApp/1.0 Me"}
$Client = New-Object -TypeName Meraki.Api.MerakiClient -ArgumentList $Options $logger
$Organizations = await $Client::Organizations.GetOrganizationsAsync([System.Threading.CancellationToken]::None)