Share via

Is there a way to use PowerShell to run through a specific list of customer tenants in lighthouse and get monitor information?

Marianda Potgieter 0 Reputation points
2026-02-13T07:09:10.0633333+00:00

I have a a list of clients that I need to manage, I want a PowerShell script that I can use to automate getting CPU, Memory, disk space, backups completed etc.. (if possible other details too like NSG rules currently in place).

I have read previously asked questions and believe this could be possible using the Managed Services cmdlet but I'm not sure how to run through multiple clients using one script - and if using that module will actually allow me to pull data like that or allow me to connect to multiple clients, logging in with my CSP account (via lighthouse) not my specific tenant account.

(not having to authenticate every single time a new customer is queried)

Some resources I have gone through:

https://www.sharepointdiary.com/2015/06/send-mailmessage-powershell-body-html-format.html

https://4sysops.com/archives/building-html-reports-in-powershell-with-convertto-html/

https://learn.microsoft.com/en-us/azure/lighthouse/how-to/monitor-at-scalehttps://learn.microsoft.com/en-us/answers/questions/1657764/azure-lighthouse-powershell

https://learn.microsoft.com/en-us/azure/lighthouse/how-to/monitor-at-scale * like this but not having to authenticate every time.

Azure Lighthouse
Azure Lighthouse

An Azure service that provides secure managed services and access control for partners and customers.

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Siva shunmugam Nadessin 5,950 Reputation points Microsoft External Staff Moderator
    2026-02-13T09:37:47.83+00:00

    Hello Marianda Potgieter,

    Thank you for reaching out to the Microsoft Q&A forum.

    It sounds like you're looking to automate the process of collecting performance and configuration data from multiple customer tenants using PowerShell and Azure Lighthouse. Here’s a general approach you can take to achieve this:

    Step-by-Step Process

    Set Up PowerShell Module: First, ensure you have the Azure PowerShell module installed. You can install it using:

    Install-Module -Name Az -AllowClobber -Scope CurrentUser
    

    Authenticate with Azure: When using Azure Lighthouse, you will authenticate in your managing tenant and connect to the customer tenants without needing to log in each time.

    Connect-AzAccount
    

    List of Customer Tenants: Prepare a list of your customer tenant IDs. You can store these in an array for iteration. For example:

    $customerTenants = @("tenantID1", "tenantID2", "tenantID3")
    

    Loop Through Each Tenant: Use a loop to go through each tenant and run your desired queries. Here’s a basic example to collect CPU, Memory, and Disk information:

    foreach ($tenant in $customerTenants) {
        # Switch to the customer tenant
        Set-AzContext -TenantId $tenant
        # Get monitoring data (replace with your specific commands)
        # Example: Get CPU and Memory Usage
         $vmMetrics = Get-AzVM | ForEach-Object {
         Get-AzVMSize -ResourceGroupName $_.ResourceGroupName -VMName $_.Name
    } 
    # Output the metrics or store them as needed
    $vmMetrics | Export-Csv -Path "monitoringData_$($tenant).csv"
    }
    

    Additional Data Collection: For NSG rules or backup information, you can utilize other relevant cmdlets:

    NSG Rules

    Get-AzNetworkSecurityGroup
    

    Backup Status: Depending on your setup, you might need to use Azure Backup cmdlets.

    Additional Considerations

    Error Handling: Implement error handling within your loop to account for potential issues when querying each tenant.

    Optimizing Performance: If you have a large number of tenants, consider running queries asynchronously.

    Reporting: After data collection, you can format the output as needed using ConvertTo-Html or similar commands to generate reports.

    Useful Documentation Links

    Let us know if you have further questions?


  2. Q&A Assist
    2026-02-13T07:09:26.2666667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To automate the retrieval of monitoring information across multiple customer tenants using Azure Lighthouse, you can utilize PowerShell scripts along with the Azure PowerShell module. Here are the steps you can follow:

    1. Use Azure PowerShell: Ensure you have the Azure PowerShell module installed and that you are authenticated with your CSP account. This will allow you to manage multiple tenants without needing to authenticate each time.
    2. Get List of Customer Tenants: You can retrieve the list of customer tenants you manage using the Get-AzSubscription cmdlet. This will help you loop through each tenant.
    3. Query Monitoring Information: For each tenant, you can use the appropriate cmdlets to gather CPU, memory, disk space, and other metrics. You might need to use Azure Monitor or Azure Resource Graph to get specific details like NSG rules.
    4. Automate the Process: Write a script that iterates through each tenant, collects the required data, and compiles it into a report.

    Here’s a simplified example of what the script structure might look like:

    # Connect to Azure with your CSP account
    Connect-AzAccount -UseDeviceAuthentication
    
    # Get all subscriptions (tenants)
    $tenants = Get-AzSubscription
    
    foreach ($tenant in $tenants) {
        # Set the context to the current tenant
        Set-AzContext -SubscriptionId $tenant.Id
    
        # Get monitoring data (example for CPU usage)
        $cpuData = Get-AzMetric -ResourceId <ResourceId> -MetricName "Percentage CPU"
        # Similarly, gather memory, disk space, etc.
    
        # Get NSG rules
        $nsgRules = Get-AzNetworkSecurityGroup -ResourceGroupName <ResourceGroupName>
    
        # Compile results
        # (Add your logic to compile and format the results)
    }
    

    Make sure to replace <ResourceId> and <ResourceGroupName> with actual values relevant to your environment. This script will allow you to gather data without needing to authenticate for each tenant.

    For more detailed guidance, you can refer to the Azure documentation on monitoring at scale using Azure Lighthouse.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.