This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
PartnerCenterPartner.psm1
98 lines (80 loc) · 4.14 KB
/
PartnerCenterPartner.psm1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Set-StrictMode -Version latest
<#
© 2018 Microsoft Corporation. All rights reserved. This sample code is not supported under any Microsoft standard support program or service.
This sample code is provided AS IS without warranty of any kind. Microsoft disclaims all implied warranties including, without limitation,
any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance
of the sample code and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation,
production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business
profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the
sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
#>
# Load common code
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$here\commons.ps1"
<#
.SYNOPSIS
Returns audit records based on the specified time.
.DESCRIPTION
The Get-PCAuditRecord cmdlet retrieves a list of audit records for the specified time period.
.PARAMETER SaToken
Specifies an authentication token with your Partner Center credentials.
.PARAMETER StartDate
The date from which you will start retrieving data. Must be formated yyyy-mm-dd.
.PARAMETER EndDate
The date from which you will stop retrieving data. Must be formated yyyy-mm-dd.
.EXAMPLE
Get-PCAuditRecord
.NOTES
#>
function Get-PCAuditRecord {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)][ValidatePattern("\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])*")][string]$StartDate,
[Parameter(Mandatory = $false)][ValidatePattern("\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])*")][string]$EndDate,
#[Parameter(Mandatory = $false)][string]$filter,
[Parameter(Mandatory = $false)][string]$SaToken = $GlobalToken
)
_testTokenContext($SaToken)
$obj = @()
# TODO Only 30 days can be returned per request, limit the request to 30 days span before executing request
if ($startDate) { $url = "https://api.partnercenter.microsoft.com/v1/auditrecords?startDate={0}" -f $StartDate }
if ($endDate) { $url = "https://api.partnercenter.microsoft.com/v1/auditrecords?startDate={0}&endDate={1}" -f $StartDate, $EndDate }
#if ($filter)
#{
# [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
# $filter = [System.Web.HttpUtility]::UrlEncode($filter)
# $url = "https://api.partnercenter.microsoft.com/v1/auditrecords?startDate={0}&endDate={1}&filter={2}" -f $startDate, $endDate, $filter
#}
$headers = New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'
$headers.Add("Authorization", "Bearer $SaToken")
$headers.Add("MS-PartnerCenter-Application", $ApplicationName)
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method "GET" #-Debug -Verbose
$obj += $response.items
return (_formatResult -obj $obj -type "AuditRecord")
}
<#
.SYNOPSIS
Returns a list of indirect resellers.
.DESCRIPTION
The Get-PCIndirectReseller cmdlet.
.PARAMETER SaToken
Specifies an authentication token with your Partner Center credentials.
.EXAMPLE
Get-PCIndirectReseller
.NOTES
#>
function Get-PCIndirectReseller {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)][string]$SaToken = $GlobalToken
)
_testTokenContext($SaToken)
$obj = @()
$url = "https://api.partnercenter.microsoft.com/v1/relationships?relationship_type=IsIndirectCloudSolutionProviderOf"
$headers = New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'
$headers.Add("Authorization", "Bearer $SaToken")
$headers.Add("MS-PartnerCenter-Application", $ApplicationName)
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method "GET" #-Debug -Verbose
$obj += $response.Substring(1) | ConvertFrom-Json
return (_formatResult -obj $obj -type "PartnerRelationship")
}