Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question/Feedback]: Handling multiple subscriptions in AVD pattern runbook #289

Open
1 task done
abkgaard opened this issue Jul 25, 2024 · 0 comments
Open
1 task done
Assignees
Labels
Pattern: AVD Issues / PR's related to the AVD Pattern question Further information is requested

Comments

@abkgaard
Copy link

Check for previous/existing GitHub issues

  • I have checked for previous/existing GitHub issues

Description

For the runbooks that are supposed to collect data from host pools and storage accounts, the context is not changed when querying through storage accounts. Also I find that the default subscription may be different, than the one that they reside in.

For the hostpool runbook, since it takes subscriptionId as a parameter, we could set the context to that subscription ID.

[CmdletBinding(SupportsShouldProcess)]
param(
	[Parameter(Mandatory)]
	[string]$CloudEnvironment,
    [Parameter(Mandatory)]
    [string]$SubscriptionId
)

Connect-AzAccount -Identity -Environment $CloudEnvironment | Out-Null

#### Add this line
Set-AzContext -SubscriptionId $SubscriptionId

$AVDHostPools = Get-AzWvdHostPool -SubscriptionId $SubscriptionId

For the storage account runbook, I suggest to handle it in the foreach - if our context is incorrect, correct it and then walk through the commands:

# Foreach storage account
Foreach ($storageAcct in $storageAccountResourceIDs) {


    ##### Context handling - add this block
    $Subscription = (Get-azSubscription -SubscriptionId ($StorageAccountResourceIDs -split '/')[2])
    $SubName = $Subscription.Name
    
    #Get current context
    $Context = Get-AzContext
    if ($Context.Subscription.Id -ne $Subscription.Id) {
        Set-AzContext -SubscriptionId $Subscription.Id
        Write-Output "Changed context to subscription $($Subscription.Name) $($Subscription.Id)"
    } 

    ##### Context handling

    $resourceGroup = ($storageAcct -split '/')[4]
    $storageAcctName = ($storageAcct -split '/')[8]
    #Write-Host "Working on Storage:" $storageAcctName "in" $resourceGroup
@abkgaard abkgaard added the question Further information is requested label Jul 25, 2024
@Brunoga-MS Brunoga-MS added the Pattern: AVD Issues / PR's related to the AVD Pattern label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pattern: AVD Issues / PR's related to the AVD Pattern question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants