Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rink-turksma authored Aug 27, 2024
1 parent 4d4c6ea commit 4690c38
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions addAppRegPlainText.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2024 v5.8.238
Created on: 27-8-2024 16:39
Created by: Rink Turksma
Organization:
Filename: addAppRegPlainText.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
param
(
[parameter(Mandatory = $true)]
[string]$appRegName,
[string]$customername
)
#Requires -RunAsAdministrator
Import-Module -Name IntuneWin32App -RequiredVersion 1.4.4 -Force
Import-Module -Name Microsoft.Graph.Authentication -RequiredVersion 2.18.0 -Force
Import-Module -Name Microsoft.Graph.Applications -RequiredVersion 2.18.0 -Force
Import-Module -Name Microsoft.Graph.Identity.SignIns -RequiredVersion 2.18.0 -Force

$customerloc = "C:\Users\$env:username\.IntunePrepTool\$customername.csv"


class config_tenantinfo {
[string]$customername
[string]$appRegName
[string]$tenantID
[string]$appId
[string]$clientsecret
[datetime]$validdate
}


Connect-MgGraph -Scopes "Application.Read.All", "Application.ReadWrite.All", "User.Read.All", "Application.ReadWrite.All", "AppRoleAssignment.ReadWrite.All" -ContextScope Process -NoWelcome
$tenantInfo = Get-MgContext

$requiredResourceAccess = @{
'resourceAccess' = @(
@{
'id' = "78145de6-330d-4800-a6ce-494ff2d33d07"
'type' = "Role"
},
@{
'id' = "01d4889c-1287-42c6-ac1f-5d1e02578ef6"
'type' = "Role"
}



)
'resourceAppId' = "00000003-0000-0000-c000-000000000000"
}
try
{
$appInfo = New-MgApplication -DisplayName $appRegName -RequiredResourceAccess $requiredResourceAccess
}
catch
{
$_.Exception | Format-List -Force
$_.Exception.InnerException
}


$appId = $appInfo.Id
$appID2 = Get-MgApplication -ApplicationId $appID
$passwordCredential = @{
"displayName" = $appRegName
"endDateTime" = (Get-Date).AddMonths(+ 12)
}
$clientSecret = Add-MgApplicationPassword -ApplicationId ($appInfo.Id) -PasswordCredential $passwordCredential

$tenantID = $tenantInfo.TenantId
$appID = $appInfo.AppId
$clientSecret = $clientSecret.SecretText
$username = $appInfo.AppId
$password = $clientSecret.SecretText
$config_tenantinfo = $null;
$config_tenantinfo += @([config_tenantinfo]@{
customername = $customername
appRegName = $appRegName
tenantID = $tenantID
appID = $appId
clientsecret = $clientSecret
validdate = (Get-Date).AddMonths(+ 12)

})





$graphSpId = $(Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'").Id
$sp = New-MgServicePrincipal -AppId $appInfo.appId
try
{
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -PrincipalId $sp.Id -AppRoleId "78145de6-330d-4800-a6ce-494ff2d33d07" -ResourceId $graphSpId -erroraction Stop
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -PrincipalId $sp.Id -AppRoleId "01d4889c-1287-42c6-ac1f-5d1e02578ef6" -ResourceId $graphSpId -erroraction Stop
write-host "App Registration done!"
$config_tenantinfo2 = [PSCustomObject]@{ customername = $customername; target = "plain"}
$config_tenantinfo2 | Export-Csv "c:\users\$env:username\.IntunePrepTool\config_tenantinfo.csv" -NoTypeInformation -append
$config_tenantinfo | export-csv $customerloc -NoTypeInformation -Force
}
catch
{
$_.Exception | Format-List -Force
$_.Exception.InnerException
}

0 comments on commit 4690c38

Please sign in to comment.