diff --git a/azure_jumpstart_hcibox/artifacts/PowerShell/Bootstrap.ps1 b/azure_jumpstart_hcibox/artifacts/PowerShell/Bootstrap.ps1 index 6c8ec7ab1d..6dd133edba 100644 --- a/azure_jumpstart_hcibox/artifacts/PowerShell/Bootstrap.ps1 +++ b/azure_jumpstart_hcibox/artifacts/PowerShell/Bootstrap.ps1 @@ -73,9 +73,6 @@ Start-Transcript -Path "$($HCIBoxConfig.Paths["LogsDir"])\Bootstrap.log" Write-Host "Extending C:\ partition to the maximum size" Resize-Partition -DriveLetter C -Size $(Get-PartitionSupportedSize -DriveLetter C).SizeMax -# Installing Posh-SSH PowerShell Module -# Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - # Installing tools Write-Header "Installing Chocolatey Apps" try { @@ -210,5 +207,5 @@ Install-WindowsFeature -Name Hyper-V -IncludeAllSubFeature -IncludeManagementToo # Clean up Bootstrap.log Write-Header "Clean up Bootstrap.log." Stop-Transcript -$logSuppress = Get-Content $($HCIBoxConfig.Paths["LogsDir"])\Bootstrap.log | Where-Object { $_ -notmatch "Host Application: powershell.exe" } -$logSuppress | Set-Content $($HCIBoxConfig.Paths["LogsDir"])\Bootstrap.log -Force +$logSuppress = Get-Content $($HCIBoxConfig.Paths.LogsDir)\Bootstrap.log | Where-Object { $_ -notmatch "Host Application: powershell.exe" } +$logSuppress | Set-Content $($HCIBoxConfig.Paths.LogsDir)\Bootstrap.log -Force diff --git a/azure_jumpstart_hcibox/artifacts/PowerShell/Generate-ARM-Template.ps1 b/azure_jumpstart_hcibox/artifacts/PowerShell/Generate-ARM-Template.ps1 index 369e751988..eec4d35af5 100644 --- a/azure_jumpstart_hcibox/artifacts/PowerShell/Generate-ARM-Template.ps1 +++ b/azure_jumpstart_hcibox/artifacts/PowerShell/Generate-ARM-Template.ps1 @@ -14,15 +14,10 @@ Write-Host 'Creating credentials and connecting to Azure' $azureAppCred = (New-Object System.Management.Automation.PSCredential $env:spnClientID, (ConvertTo-SecureString -String $env:spnClientSecret -AsPlainText -Force)) Connect-AzAccount -ServicePrincipal -Subscription $env:subscriptionId -Tenant $env:spnTenantId -Credential $azureAppCred -# Check that extensions are finished installing on HCI nodes -# foreach ($node in $HCIBoxConfig.NodeHostConfig) { - -# } - # Install some modules Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Install-Module -Name Az.Resources -Force -Install-Module Az.ConnectedMachine -Force +Install-Module -Name Az.Resources -AllowClobber -Force +Install-Module -Name Az.ConnectedMachine -AllowClobber -Force Import-Module -Name Az.Resources, Az.ConnectedMachine -Force # Add necessary role assignments diff --git a/azure_jumpstart_hcibox/artifacts/PowerShell/New-HCIBoxCluster.ps1 b/azure_jumpstart_hcibox/artifacts/PowerShell/New-HCIBoxCluster.ps1 index c3d697a4c6..c8307cff3a 100644 --- a/azure_jumpstart_hcibox/artifacts/PowerShell/New-HCIBoxCluster.ps1 +++ b/azure_jumpstart_hcibox/artifacts/PowerShell/New-HCIBoxCluster.ps1 @@ -81,6 +81,7 @@ function GenerateAnswerFile { ) $formattedMAC = Get-FormattedWACMAC -HCIBoxConfig $HCIBoxConfig + $encodedPassword = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($($HCIBoxConfig.SDNAdminPassword) + "AdministratorPassword")) $wacAnswerXML = @" @@ -150,8 +151,8 @@ function GenerateAnswerFile { -$($HCIBoxConfig.SDNAdminPassword) -true</PlainText> +<PlainText>false</PlainText> +<Value>$encodedPassword</Value> </AdministratorPassword> </UserAccounts> <TimeZone>UTC</TimeZone> @@ -283,8 +284,8 @@ $components</settings> </OOBE> <UserAccounts> <AdministratorPassword> -<Value>$($HCIBoxConfig.SDNAdminPassword)</Value> -<PlainText>true</PlainText> +<PlainText>false</PlainText> +<Value>$encodedPassword</Value> </AdministratorPassword> </UserAccounts> </component> diff --git a/azure_jumpstart_hcibox/artifacts/hci.json b/azure_jumpstart_hcibox/artifacts/hci.json index 42933f2ac0..d75f7e2e71 100644 --- a/azure_jumpstart_hcibox/artifacts/hci.json +++ b/azure_jumpstart_hcibox/artifacts/hci.json @@ -463,7 +463,7 @@ "identity": { "type": "SystemAssigned" }, - "location": "[parameters('location')]", + "location": "eastus", "properties": { } }, diff --git a/azure_jumpstart_hcibox/scripts/preprovision.ps1 b/azure_jumpstart_hcibox/scripts/preprovision.ps1 index fefa2bd052..de4b3aa92f 100644 --- a/azure_jumpstart_hcibox/scripts/preprovision.ps1 +++ b/azure_jumpstart_hcibox/scripts/preprovision.ps1 @@ -12,14 +12,14 @@ if (-not (Get-Command -Name Get-AzContext)) { # If not signed in, run the Connect-AzAccount cmdlet if (-not (Get-AzContext)) { - Write-Host "Logging in to Azure..." + Write-Host "Logging in to Azure with subscription id $env:AZURE_SUBSCRIPTION_ID" If (-not (Connect-AzAccount -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -ErrorAction Stop)){ Throw "Unable to login to Azure. Please check your credentials and try again." } } $tenantId = (Get-AzContext).tenant.id -# Write-Host "Setting Azure context..." -$context = Set-AzContext -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -Tenant $tenantId -ErrorAction Stop +Write-Host "Setting Azure context with subscription id $env:AZURE_SUBSCRIPTION_ID and tenant id $tenantId..." +$context = Set-AzContext -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -ErrorAction Stop # Write-Host "Setting az subscription..." az account set --subscription $env:AZURE_SUBSCRIPTION_ID @@ -165,7 +165,7 @@ azd env set JS_RDP_PORT $JS_RDP_PORT # Attempt to retrieve provider id for Microsoft.AzureStackHCI Write-Host "Attempting to retrieve Microsoft.AzureStackHCI provider id..." -$spnProviderId=$(az ad sp list --display-name "Microsoft.AzureStackHCI") | ConvertFrom-Json +$spnProviderId=$(az ad sp list --display-name "Microsoft.AzureStackHCI" --output json) | ConvertFrom-Json if ($null -ne $spnProviderId.id) { azd env set SPN_PROVIDER_ID -- $($spnProviderId.id) } @@ -177,7 +177,7 @@ Write-Host "Checking for existing stored Azure service principal..." if ($null -ne $env:SPN_CLIENT_ID) { Write-Host "Re-using existing service principal..." } else { - Write-Host "Attempting to create new service principal..." + Write-Host "Attempting to create new service principal with scope /subscriptions/$($env:AZURE_SUBSCRIPTION_ID)..." $user = (Get-AzContext).Account.Id.split("@")[0] $uniqueSpnName = "$user-jumpstart-spn-$(Get-Random -Minimum 1000 -Maximum 9999)" try { @@ -191,14 +191,12 @@ if ($null -ne $env:SPN_CLIENT_ID) { azd env set SPN_TENANT_ID -- $SPN_TENANT_ID } catch { + If ($error[0].ToString() -match "Forbidden"){ Throw "You do not have permission to create a service principal. Please contact your Azure subscription administrator to grant you the Owner role on the subscription." } - elseif ($error[0].ToString() -match "credentials") { - Throw "Please run Connect-AzAccount to sign in and run 'azd up' again." - } else { - Throw "An error occurred creating the service principal. Please try again." + Throw "An error occurred creating the service principal. Error:" + $error[0].ToString() } }