Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatic Provisioning Power Platform Hands-on-Labs Environment
Install-Module -Name AzureAD `
-Scope AllUsers -Repository PSGallery `
-Force -AllowClobber
$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
$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
}
$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 }
}
$users | ForEach-Object {
$assigned = Add-AzureADDirectoryRoleMember `
-ObjectId $role.ObjectId `
-RefObjectId $_.ObjectId
}
Get-AzureADSubscribedSku
$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
}
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
$connected = Add-PowerAppsAccount -Username $adminUpn -Password $adminPW
$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
}
$connected = Connect-AzAccount -Credential $adminCredential
Install-Module -Name Az -Scope AllUsers -Repository PSGallery -Force -AllowClobber
$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 $_
}
}
$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
}
./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