Last active
July 6, 2021 07:49
-
-
Save justinyoo/4cba9e122dfdb5684cd432c072b36b3d to your computer and use it in GitHub Desktop.
Automatic Provisioning Power Platform Hands-on-Labs Environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install-Module -Name AzureAD ` | |
| -Scope AllUsers -Repository PSGallery ` | |
| -Force -AllowClobber |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $tenantName = "powerplatformhandsonlab" | |
| $adminUpn = "admin@$tenantName.onmicrosoft.com" | |
| $adminPW = ConvertTo-SecureString "Pa`$`$W0rd!@#`$" -AsPlainText -Force | |
| $adminCredential = New-Object ` | |
| -TypeName System.Management.Automation.PSCredential ` | |
| -ArgumentList ($adminUpn, $adminPW) | |
| $connected = Connect-AzureAD -Credential $adminCredential |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $userPWProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile | |
| $userPWProfile.Password = "UserPa`$`$W0rd!@#`$" | |
| $userPWProfile.EnforceChangePasswordPolicy = $false | |
| $userPWProfile.ForceChangePasswordNextLogin = $false | |
| $usageLocation = "KR" | |
| $users = @() | |
| (1..24) | ForEach-Object { | |
| $user = New-AzureADUser ` | |
| -DisplayName $("PPUser" + $_.ToString("00")) -GivenName $("User" + $_.ToString("00")) -SurName "PP" ` | |
| -UserPrincipalName $("ppuser" + $_.ToString("00") + "@$tenantName.onmicrosoft.com") ` | |
| -UsageLocation $usageLocation ` | |
| -MailNickName $("ppuser" + $_.ToString("00")) ` | |
| -PasswordProfile $userPWProfile ` | |
| -AccountEnabled $true | |
| $users += $user | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $roleName="Power Platform Administrator" | |
| $role = Get-AzureADDirectoryRole | Where-Object { $_.DisplayName -eq $roleName } | |
| if ($role -eq $null) { | |
| $roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object { $_.DisplayName -eq $roleName } | |
| $enabled = Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId | |
| $role = Get-AzureADDirectoryRole | Where-Object { $_.DisplayName -eq $roleName } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $users | ForEach-Object { | |
| $assigned = Add-AzureADDirectoryRoleMember ` | |
| -ObjectId $role.ObjectId ` | |
| -RefObjectId $_.ObjectId | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Get-AzureADSubscribedSku |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $sku = Get-AzureADSubscribedSku | |
| $license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense | |
| $license.SkuId = $sku.SkuId | |
| $licensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses | |
| $licensesToAssign.AddLicenses = $license | |
| $users | ForEach-Object { | |
| $assigned = Set-AzureADUserLicense -ObjectId $_.ObjectId -AssignedLicenses $licensesToAssign | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install-Module -Name Microsoft.PowerApps.Administration.PowerShell ` | |
| -Scope AllUsers -Repository PSGallery ` | |
| -Force -AllowClobber | |
| Install-Module -Name Microsoft.PowerApps.PowerShell ` | |
| -Scope AllUsers -Repository PSGallery ` | |
| -Force -AllowClobber |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $connected = Add-PowerAppsAccount -Username $adminUpn -Password $adminPW |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $paenv = Get-AdminPowerAppEnvironment -Default | |
| if ($paenv.CommonDataServiceDatabaseProvisioningState -ne "Succeeded") { | |
| $currency = Get-AdminPowerAppCdsDatabaseCurrencies ` | |
| -LocationName $paenv.Location | Where-Object { | |
| $_.IsTenantDefaultCurrency -eq $true | |
| } | |
| $language = Get-AdminPowerAppCdsDatabaseLanguages ` | |
| -LocationName $paenv.Location | Where-Object { | |
| $_.IsTenantDefaultLanguage -eq $true | |
| } | |
| $activated = New-AdminPowerAppCdsDatabase ` | |
| -EnvironmentName $paenv.EnvironmentName ` | |
| -CurrencyName $currency.CurrencyName ` | |
| -LanguageName $language.LanguageName | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $connected = Connect-AzAccount -Credential $adminCredential |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install-Module -Name Az -Scope AllUsers -Repository PSGallery -Force -AllowClobber |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $namespaces = @( | |
| "Microsoft.Logic", | |
| "Microsoft.Storage", | |
| "Microsoft.Network", | |
| "Microsoft.ApiManagement", | |
| "Microsoft.DocumentDB" | |
| ) | |
| $namespaces | ForEach-Object { | |
| $provider = Get-AzResourceProvider ` | |
| -ProviderNamespace $_ | Where-Object { $_.RegistrationState -eq "Registered" } | |
| if (($provider -eq $null) -or ($provider.Count -eq 0)) { | |
| $registered = Register-AzResourceProvider -ProviderNamespace $_ | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $role = Get-AzRoleDefinition | Where-Object { $_.Name -eq "Contributor" } | |
| $location = "koreacentral" | |
| $users | ForEach-Object { | |
| $rg = Get-AzResourceGroup | Where-Object { | |
| $_.ResourceGroupName -eq $("rg-" + $_.MailNickName) | |
| } | |
| if ($rg -eq $null) { | |
| $rg = New-AzResourceGroup ` | |
| -Name $("rg-" + $_.MailNickName) ` | |
| -Location $location | |
| } | |
| $assigned = New-AzRoleAssignment ` | |
| -ObjectId $_.ObjectId ` | |
| -RoleDefinitionId $role.Id ` | |
| -Scope $rg.ResourceId | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ./Set-Environment.ps1 ` | |
| -AdminUsername "admin" ` | |
| -AdminPassword "Pa`$`$W0rd!@#`$" ` | |
| -TenantName "powerplatformhandsonlab" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment