Public/New-GraphApplication.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<#
    .NOTES
    ===========================================================================
     Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
     Created on: 2/8/2017 7:34 AM
     Created by: Mark Kraus
     Organization: Mitel
     Filename: New-GraphApplication.ps1
    ===========================================================================
    .DESCRIPTION
        New-GraphApplication Function
#>


<#
    .SYNOPSIS
        Creates a Graph Application object
    
    .DESCRIPTION
        Creates a Graph Application object containing data used by various cmdltes to define the parameters of the App registered on Azure AD. This does not make any calls to Azure or the Gtaph API. The Application will be inbeded in the Graph OAuthToken objects.
        The MSGraphAPI.Application object contains the following properties:
        Name Name of the Application
        Description Description of the Application
        UserAgent The User-Agent header the Application will use to access the Graph API
        ClientID The Client ID of the Registered Azure App
        RedirectUri The Redirect URI of the Registered Azure App
        ClientCredential A PS Crednetial containing the Client ID as the username and the Client Secret as the password
        UserCredential The Reddit Username and password of the developer account used for a Script application
        GUID A GUID to identitfy the application wihin this module (not consumed or used by Azure or Graph)
    
    .PARAMETER Name
        Name of the Graph App. This does not need to match the name registered on Azure. It is used for convenient identification and ducomentation purposes only.
    
    .PARAMETER ClientCredential
        A PScredential object containging the Client ID as the Username and the Client Secret as the password.
    
    .PARAMETER RedirectUri
        Redirect URI as registered on Azure for the App. This must match exactly as entered in the App definition or authentication will fail.

    .PARAMETER Tenant
        The Azure/Office365 Tenant ID. e.g. adadtum.onmicrosft.com
    
    .PARAMETER Description
        Description of the Graph App. This is not required or used for anything. It is provided for convenient identification and documentation purposes only.
    
    .PARAMETER GUID
        A GUID to identify the application. If one is not perovided, a new GUID will be generated.
    
    .EXAMPLE
        PS C:\> $ClientCredential = Get-Credential
        PS C:\> $Params = @{
        Name = 'MyGraphApp'
        Description = 'My Graph Application!'
        ClientCredential = $ClientCredential
        RedirectUri = 'https://adataum/ouath?'
        UserAgent = 'Windows:PowerShell:GraphApplication'
        }
        PS C:\> $GraphApp = New-GraphApplication @Params
    
    .OUTPUTS
        MSGraphAPI.Application
    
    .LINK
        http://psmsgraph.readthedocs.io/en/latest/functions/New-GraphApplication
    .LINK
        http://psmsgraph.readthedocs.io/en/latest/functions/Export-GraphApplication
    .Link
        http://psmsgraph.readthedocs.io/en/latest/functions/Import-GraphApplication
#>

function New-GraphApplication {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification = "Creates in memory object only.")]
    [CmdletBinding(ConfirmImpact = 'None',
                   HelpUri = 'http://psmsgraph.readthedocs.io/en/latest/functions/New-GraphApplication')]
    [OutputType('MSGraphAPI.Application')]
    param
    (
        [Parameter(Mandatory = $true,
                   ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [Alias('AppName')]
        [string]$Name,
        
        [Parameter(Mandatory = $true,
                   ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [Alias('ClientInfo')]
        [System.Management.Automation.PSCredential]$ClientCredential,
        
        [Parameter(Mandatory = $true,
                   ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [ValidateScript({
                [system.uri]::IsWellFormedUriString(
                    $_, [System.UriKind]::Absolute
                )
            })]
        [string]$RedirectUri,
        
        [Parameter(Mandatory = $True,
                   ValueFromPipelineByPropertyName = $true)]
        [string]$Tenant,
        
        [Parameter(Mandatory = $false,
                   ValueFromPipelineByPropertyName = $true)]
        [string]$Description,
        
        [Parameter(Mandatory = $false,
                   ValueFromPipelineByPropertyName = $true)]
        [System.Guid]$GUID = [system.guid]::NewGuid()
    )
    
    Process {
        
        [pscustomobject]@{
            PSTypeName = 'MSGraphAPI.Application'
            Name = $Name
            Description = $Description
            ClientCredential = $ClientCredential
            RedirectUri = $RedirectUri
            Tenant = $Tenant
            GUID = $GUID
        }
    }
}