Public/New-VSAApplication.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
function New-VSAApplication {
    [CmdletBinding()]
    Param
    (
        [parameter(Position = 0, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$PackageName,
        
        [parameter(Position = 1, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$PackageVersion,
        
        [parameter(Position = 2, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$PackageInstallCmd,

        [parameter(Position = 3, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$PackageUninstallCmd,

        [parameter(Position = 4, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$PackageDetectionPath,

        [parameter(Position = 4, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$PackageDetectionFile,

        [parameter(Position = 5, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$TenantID,

        [parameter(Position = 5, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][String]$IntuneWinPath,

        [parameter(Position = 5, Mandatory = $true)]
        [ValidateNotNullOrEmpty()][bool]$OverwriteExisting

    )
    Write-Verbose "Getting a list of all tenants"
    Connect-GraphAPI -ApplicationId $ApplicationId -ApplicationSecret $ApplicationSecret -Tenantid $TenantID
    $Tenants = New-GraphRequest -resource "contracts"
    foreach ($Tenant in $Tenants) {
        try {
            Connect-GraphAPI -Tenantid $TenantID
            $params = @{
                packagename           = $PackageName 
                packageversion        = $PackageVersion
                packageinstallcmd     = $PackageInstallCmd 
                packageuninstallcmd   = $PackageUninstallCmd 
                packaagedetectionpath = $PackageDetectionPath 
                packagedetectionfile  = $PackageDetectionFile
            }
            New-IntunePackage @Params
        }
        catch {
            write-error "Failed for tenant $($tenant.defaultdomainname). Moving onto next client."
        }
    }
}