Azure Runbooks
8 TopicsRetrieving SharePoint Site Visitors Using PowerShell Script
I’m working on a PowerShell script to generate a report of Microsoft Teams details, including the owners, members, and SharePoint site visitors. While the script successfully retrieves most of the information, it fails to retrieve the site visitors, which I can clearly see in the SharePoint Admin Center. Issues: Site Visitors Not Retrieved: Despite having site visitors visible in the SharePoint Admin Center, the script returns "Error retrieving Visitors" or an empty string for site visitors. Potential Errors: I'm using a try-catch block to handle exceptions, but it seems like there are no errors being caught that could indicate why the visitors aren't being retrieved. What I’ve Tried: Ensured the SharePoint site URL is correct. Checked permissions and roles for the account running the script. Request: Could someone help identify what might be going wrong or suggest a different approach to reliably retrieve the list of SharePoint site visitors or any module I am missing on? I am using below modules with Powershell Runtime version 5.1. ExchangeOnlineManagement - Version 3.5.1 Get-MsolUserLicences - Version 0.0.8 Microsoft.Graph.Authentication - Version 2.20.0 Microsoft.Graph.Teams - Version 2.20.0 Microsoft.Graph.Users - Version 2.20.0 Microsoft.Online.SharePoint.PowerShell - Version 16.0.25012.12000 MicrosoftTeams - Version 6.4.0 MSOnline - Version 1.1.183.81 PackageManagement - Version 1.4.8.1 PnP.PowerShell - Version 2.5.0 PowerShellGet - Version 2.2.5 SharePointPnPPowerShellOnline - Version 3.29.2101.0 Any insights or recommendations would be greatly appreciated! Thanks in advance for your help. Connect-MicrosoftTeams -Credential $UserCredential -AccountId $myCredential.UserName Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true Connect-SPOService -Url "https://domain-admin.sharepoint.com" -Credential $UserCredential # Initialize an empty array to store the results $Result = @() # Get all Teams enabled groups $AllTeamsInOrg = Get-Team $Teamcount = $AllTeamsInOrg.Count foreach ($Team in $AllTeamsInOrg) { Write-Host "Processing Team $($Team.DisplayName) ..." -NoNewline -ForegroundColor Gray $TeamName = $Team.DisplayName $TeamGroupId = $Team.GroupId # Get team details $TeamOwner = (Get-TeamUser -GroupId $TeamGroupId -Role Owner).User $TeamUserCount = (Get-TeamUser -GroupId $TeamGroupId).Count $TeamGuest = (Get-TeamUser -GroupId $TeamGroupId -Role Guest).Name if ($TeamGuest -eq $null) { $TeamGuest = "No Guests in Team" } $TeamMembers = (Get-TeamUser -GroupId $TeamGroupId -Role Member).User $TeamChannels = (Get-TeamChannel -GroupId $TeamGroupId).DisplayName $ChannelCount = (Get-TeamChannel -GroupId $TeamGroupId).Count # Retrieve SharePoint site URL from the team $TeamGroup = Get-UnifiedGroup -Identity $TeamGroupId $SharePointSiteURL = $TeamGroup.SharePointSiteURL if ($SharePointSiteURL -ne $null) { try { # Get all SharePoint Online groups for the site $SiteGroups = Get-SPOSiteGroup -Site $SharePointSiteURL # Find the "Visitors" group and get its members $VisitorsGroup = $SiteGroups | Where-Object { $_.Title -eq "Visitors" } if ($VisitorsGroup) { $Visitors = Get-SPOSiteGroup -Site $SharePointSiteURL -Group $VisitorsGroup.Title | Select-Object -ExpandProperty Users $VisitorsEmails = $Visitors | Select-Object -ExpandProperty Email -join ", " $GroupsData += [pscustomobject]@{ 'Site URL' = $SharePointSiteURL 'Group Name' = $VisitorsGroup.Title 'Users' = $VisitorsEmails } } else { $GroupsData += [pscustomobject]@{ 'Site URL' = $SharePointSiteURL 'Group Name' = "Visitors" 'Users' = "No Visitors Group Found" } } } catch { Write-Host "Error processing site ${SharePointSiteURL}: $($_.Exception.Message)" -ForegroundColor Red $GroupsData += [pscustomobject]@{ 'Site URL' = $SharePointSiteURL 'Group Name' = "Visitors" 'Users' = "Access Denied or Error" } } } else { $GroupsData += [pscustomobject]@{ 'Site URL' = $SharePointSiteURL 'Group Name' = "Visitors" 'Users' = "No SharePoint Site URL" } } # Add team details to the $Result array $Result += [PSCustomObject]@{ TeamName = $TeamName TeamOwners = $TeamOwner -join ', ' TeamMemberCount = $TeamUserCount TeamMembers = $TeamMembers -join ', ' NoOfChannels = $ChannelCount ChannelNames = $TeamChannels -join ', ' SharePointSite = $SharePointSiteURL AccessType = $TeamGroup.AccessType TeamGuests = $TeamGuest -join ',' SharePointSiteVisitors = $SharePointSiteVisitors } Write-Host "done." -ForegroundColor Green }967Views0likes0CommentsNeed help with Azure VM reboot which checks users logged in.
Hi guys, I have been looking for methods to restart AVD using runbooks and automation. I have info on how to restart VMS, but I want to restart the VMs such that it checks if any users are logged in and if the users are logged in. It won't restart. This is the script that I found to restart from linkedin: https://www.linkedin.com/pulse/scheduling-reboot-azure-virtual-machines-using-automation-rabea/: workflow demo { InlineScript { Connect-AzAccount -Identity Restart-AzVM -ResourceGroupName "Resource Group name" -Name "VM1 name" Restart-AzVM -ResourceGroupName "Resource Group name" -Name "VM2 name" Restart-AzVM -ResourceGroupName "Resource Group name" -Name "VM3 name" } }840Views0likes4CommentsMethod not found 'Void Microsoft.Graph.TokenCredentialAuthProvider'
Hello, I try to run a runbook in Hybrid Worker to collect info from Azure Registered Apps. For that activity I connect to MS Graph with certificate and execute Get-MgApplication cmdlet. However, I see "Welcome to Microsoft Graph!" response and then: Get-MgApplication : Method not found: 'Void Microsoft.Graph.TokenCredentialAuthProvider..ctor(Azure.Core.TokenCredential, System.Collections.Generic.IEnumerable`1<System.String>)'. At line:24 char:1 + $SApps = Get-MgApplication -all + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-MgApplication_List], MissingMethodException + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgApplication_List My current version module is 2.0.0-preview5, but I also tried other versions and got different results (but never successful). All cmdlets, including connecting via certificate, can be executed successfully locally and within Azure runbook. I run out of ideas. Any ideas?9.9KViews0likes6CommentsHow to authenticate PowerShell cmdlets in Runbooks with managed identities?
Hi there. This is regarding Azure Automation Runbooks. I'm attempting to replace AzureRunAs connections with user/system managed identities. One problem I ran into with this is that I have no idea how to get the PowerShell cmdlet's used in those Runbooks to authenticate. For example for a Runbook that relies on the ExchangeOnline cmdlet's I was able to use the AzureRunAs connections credentials via Get-AutomationConnection –Name "AzureRunAsConnection". Since this AzureRunAs connection is also an App Registration in Azure, I could assign API permissions to them, like for ExchangeOnline. The AzureRunAs connection also comes with a certificate that I could make use of for authentication purposes. On way I thought I could achieve this is for example with: Copy Connect-ExchangeOnline -ManagedIdentity -Organization <tenant>.onmicrosoft.com -ManagedIdentityAccountId <id> So to summarize, my question is: How should I authenticate PowerShell cmdlet's without AzureRunAs connections in Runbooks? Thanks for your help.2.1KViews0likes2CommentsCannot connect to Exchange Online module via Runbook
That's very strange error that I came across a few times on my own workstation, but now I cannot get rid of it on Hybrid Worker machine. My runbook connects to Exchange Online to perform get-mailbox cmdlet, however at the connect-exchangeonline phase I'm getting the following error: "exception": "Could not find file 'C:\\Windows\\TEMP\\a70a8826-0c1f-4902-b1bc-767587023327\\tmpEXO_rj4fdl4e.yzc.psd1'. (Could not find file 'C:\\Windows\\TEMP\\a70a8826-0c3f-4902-b2bc-767587023327\\tmpEXO_rj4fdl4e.yzc.psd1'.)" I tried to uninstall, clean-up, restart, install previous version, nothing helps. Any ideas what could be the reason?Solved2.5KViews0likes3CommentsCert not found for Connect-MgGraph via Runbook Hybrid Worker
I use certificate to connect to Microsoft Graph and it works fine in runbooks azure instance. However, when I perform Connect-MgGraph -CertificateThumbprint <certThumbprint>-ClientID "<clientID>" -TenantID "<tenantID>" in runbook for Hybrid Worker machine I'm getting the following error: Connect-MgGraph : Certificate with subject name '[Subject] CN=CertName [Issuer] CN=CertName [Serial Number] CertSN [Not Before] 1/21/2023 1:33:10 PM [Not After] 1/21/2024 1:53:13 PM [Thumbprint] CertificateThumbPrint ' was not found in certificate store or has expired. At line:14 char:1 + Connect-MgGraph -CertificateName $cert -ClientID "<ClientID>- ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-MgGraph], ArgumentException + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph The certificate is found and data is valid, but error says "not found" anyway. I tried to specify the exact path to the certificate and use store, also I switched different graph module version, none of that helped.Solved7.1KViews0likes4CommentsAzure runbook restart during execution
Hello, I have a runbook to read all site collections from multi geolocation and get sca. There are more than 200000 site collection which needs to be processed. I am calling a child runbook from the partent runbook to get SCAs in batch of 500 site collections each. There should be around 450~500 child runbook jobs created during the excution of parent runbook. While I am executing the parent runbook, it is getting restarted from the begning during its execution. The total duration of execution of parent runbook in only 30 mins. Can anyone will help me in understaning why the parent runbook execution is getting resatrted from the begning in between? Does a fair share limit has to do with the restart of parent runbook? Regards, Ratnesh1.2KViews0likes1CommentAzure Runbook if statement does not work
In the last part of the below code block the if statement is not evaluated. The user is always added to the team no matter what the company name is. Any suggestions? Param( [string]$teamname, #The name of the Team [string]$teamowner, #The email address of the owner of the Team [string]$teamalias, #The bit of the teamname you want to be the URL [string]$external, #external sharing enabled? [string]$company #to determine site owner from IT ) #Connect to Teams PowerShell $cred = Get-AutomationPSCredential -Name "TestAdmin" $teams = Connect-MicrosoftTeams -Credential $cred #Create the Team and add owners, ensure added to address list and can be found in exchange groups $newteam = New-Team -MailNickname $teamalias -DisplayName $teamname -Owner $teamowner -Visibility Private Start-Sleep -Seconds 180 Add-TeamUser -GroupId $newteam.GroupId -User user1@domain.com -Role Owner if($company = "CompanyName1") { Add-TeamUser -GroupId $newteam.GroupId -User user2@domain.com -Role Owner }4.2KViews0likes1Comment