Skip to content

Instantly share code, notes, and snippets.

#Specify users you need to extract contactlist from.
$users = "alexander@contoso.com"
#Specify contactlist folder you need to export. Have added wildcard in the request, so if you are exporting all folders thats starts with Skype, enter "Skype" as foldername.
#Enter "root" as foldername if you want all contacts that are not in a folder.
$folder = "skype"
function Get-MSGraphAppToken{
<# .SYNOPSIS
$connection = Get-AutomationConnection -Name AzureRunAsConnection
$tenant = 'alexholmeset.onmicrosoft.com'
Connect-ExchangeOnline -CertificateThumbprint $connection.CertificateThumbprint -AppId $connection.ApplicationID -ShowBanner:$false -Organization $tenant
Get-MessageTrace
$credential = Get-AutomationPSCredential -Name 'Exchange'
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://outlook.office365.com/powershell-liveid/' -Credential $credential -Authentication Basic -AllowRedirection
Import-Module (Import-PSSession -Session $session -DisableNameChecking -AllowClobber ) -Global
$TodaysDate = Get-Date (Get-Date).AddDays(-1) -Format 'MM/dd/yyyy'
$NumberOfInternalEmails = (Get-MessageTrace -StartDate $TodaysDate -EndDate $TodaysDate | Where-Object{$_.'SenderAddress' -like '*alexholmeset.onmicrosoft.com'} | Where-Object{$_.'RecipientAddress' -like '*alexholmeset.onmicrosoft.com'}).count
#Set Defaults (Optional) which allows you to skip defining instance, user, and password each time
$AzureDefaultInstanceName = "ServerName"
$AzureDefaultDatabaseName = "DatabaseName"
$username = Get-AutomationVariable -Name 'Administrator'
$password = Get-AutomationVariable -Name 'Password'
#The actual function
$url = 'https://tas.teams.microsoft.com/v2/teams/summary-timeseries?timeperiod=last-ninety-days&includeTimeSeries=ActiveUsers&metrics=all&pagesize=20&nextCursor=null'
$token = 'CI6IjE4YzRhOTFiLTRmYTktNGZiZC1hYjFjLWIzOTQ'
$Header = @{"Authorization" = "Bearer $token" }
$data = Invoke-RestMethod -Uri $url -Method GET -Headers $Header -ContentType 'application/json'
$url = 'https://tas.teams.microsoft.com/v2/teams/summary-timeseries?timeperiod=last-ninety-days&includeTimeSeries=ActiveUsers&metrics=all&pagesize=20&nextCursor=null'
$token = 'CI6IjE4YzRhOTFiLTRmYTktNGZiZC1hYjFjLWIzOTQ'
$Header = @{"Authorization" = "Bearer $token" }
$data = Invoke-RestMethod -Uri $url -Method GET -Headers $Header -ContentType 'application/json'
#Set Defaults (Optional) which allows you to skip defining instance, user, and password each time
$AzureDefaultInstanceName = "teamssqlserver"
$AzureDefaultDatabaseName = "teamssqldatabase"
$AzureDefaultUserID = "username"
$AzureDefaultPassword = "password"
#The actual function
Function get-azureSQL (
[string]$DatabaseName = $AzureDefaultDatabaseName,
#Set Defaults (Optional) which allows you to skip defining instance, user, and password each time
$AzureDefaultInstanceName = "teamssqlserver"
$AzureDefaultDatabaseName = "teamssqldatabase"
$AzureDefaultUserID = "username"
$AzureDefaultPassword = "password"
#The actual function
Function get-azureSQL (
[string]$DatabaseName = $AzureDefaultDatabaseName,
[string]$InstanceName = $AzureDefaultInstanceName
,[string]$UserID = $AzureDefaultUserID
#Teams and SharePoint usage data consolidation script
#Author: Alexander Holmeset
#Twitter: @AlexHolmeset
function Get-MSGraphAppToken{
<# .SYNOPSIS
Get an app based authentication token required for interacting with Microsoft Graph API
.PARAMETER TenantID
A tenant ID should be provided.
#"Password!" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "D:\temp\PassordUserExpireScript.txt"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "admin@contoso", (Get-Content "d:\temp\PassordUserExpireScript.txt" | ConvertTo-SecureString)
#Gets all users thats enabled and have a expiration date.
$Users = Get-ADUser -Filter * -Properties AccountExpirationDate | select AccountExpirationDate,Enabled,UserPRincipalName,samaccountname,name | Where-Object{$_.Enabled -eq $true -and $_.AccountExpirationDate}
#Todays date.
$today = Get-Date -Format dd/MM/yyyy