Skip to content

Commit

Permalink
switch to write-host
Browse files Browse the repository at this point in the history
  • Loading branch information
sebassem committed Oct 9, 2023
1 parent 41be2b0 commit ddde439
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/scripts/Invoke-RegisterSubscriptionResourceProviders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@ $DeploymentScriptOutputs = @{}
## Registering resource providers and features
##############################################

Write-host "Starting the script"
Start-Sleep -Seconds 60

if ($providers.Count -gt 0) {
foreach ($provider in $providers.keys) {
try {
# Registering resource providers
$providerStatus = (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState
# Check if the providered is registered
if ($providerStatus -eq 'NotRegistered') {
Write-Output "`n Registering the '$provider' provider"
Write-Host "`n Registering the '$provider' provider"
if (Register-AzResourceProvider -ProviderNamespace $provider) {
Write-Output "`n The '$provider' has been registered successfully"
Write-Host "`n The '$provider' has been registered successfully"
}
else {
Write-Output "`n The '$provider' provider has not been registered successfully"
Write-Host "`n The '$provider' provider has not been registered successfully"
$failedProviders += ",$provider"
}
}
elseif ($providerStatus -eq 'Registering') {
Write-Output "`n The '$provider' provider is in registering state"
Write-Host "`n The '$provider' provider is in registering state"
$failedProviders += ",$provider"
}

Expand All @@ -50,7 +47,7 @@ if ($providers.Count -gt 0) {
$DeploymentScriptOutputs["failedProvidersRegistrations"] = $output
}
catch {
Write-Output "`n There was a problem registering the '$provider' provider. Please make sure this provider namespace is valid"
Write-Host "`n There was a problem registering the '$provider' provider. Please make sure this provider namespace is valid"
$failedProviders += ",$provider"
if ($failedProviders.length -gt 0) {
$output = $failedProviders.substring(1)
Expand All @@ -66,17 +63,17 @@ if ($providers.Count -gt 0) {
$featureStatus = (Get-AzProviderFeature -ListAvailable | Where-Object FeatureName -eq $feature).RegistrationState
# Check if the feature is registered
if ($featureStatus -eq 'NotRegistered') {
Write-Output "`n Registering the '$feature' feature"
Write-Host "`n Registering the '$feature' feature"
if (Register-AzProviderFeature -FeatureName $feature -ProviderNamespace $provider) {
Write-Output "`n The '$feature' has been registered successfully"
Write-Host "`n The '$feature' has been registered successfully"
}
else {
Write-Output "`n The '$feature' feature has not been registered successfully"
Write-Host "`n The '$feature' feature has not been registered successfully"
$failedFeatures += ",$feature"
}
}
elseif ($null -eq $featureStatus) {
Write-Output "`n The '$feature' feature doesn't exist."
Write-Host "`n The '$feature' feature doesn't exist."
$failedFeatures += ",$feature"
}
if ($failedFeatures.length -gt 0) {
Expand All @@ -88,7 +85,7 @@ if ($providers.Count -gt 0) {
$DeploymentScriptOutputs["failedFeaturesRegistrations"] = $output
}
catch {
Write-Output "`n There was a problem registering the '$feature' feature. Please make sure this feature name is valid"
Write-Host "`n There was a problem registering the '$feature' feature. Please make sure this feature name is valid"
$failedFeatures += ",$feature"
if ($failedFeatures.length -gt 0) {
$output = $failedFeatures.substring(1)
Expand All @@ -100,5 +97,5 @@ if ($providers.Count -gt 0) {
}
}
else {
Write-Output "`n No providers or features to register"
Write-Host "`n No providers or features to register"
}

0 comments on commit ddde439

Please sign in to comment.