Skip to content

Instantly share code, notes, and snippets.

View ChrFrohn's full-sized avatar

Christian Frohn ChrFrohn

View GitHub Profile
@ChrFrohn
ChrFrohn / Get-PrimarySMTPandRemoteRoutingAddress.ps1
Created June 14, 2024 08:47
Get Primary SMTP address & Remote routing address
$UserName = "" # Sample: cfp@christianfrohn.dk
Get-RemoteMailbox $UserName | Select-Object RemoteRoutingAddress, PrimarySmtpAddress
# $ObjectId can be the users AAD object ID or email adress (UPN).
param (
[Parameter (Mandatory = $true)]
[object]$ObjectIdOrUPN
)
CREATE USER [NameOfServicerincipal] FROM EXTERNAL PROVIDER;
EXEC sp_addrolemember 'db_owner', 'NameOfServicePrincipal'
$TenantId = ""
$ApplicationID = ""
$CertificateThumbprint = ""
Connect-MicrosoftTeams -CertificateThumbprint $CertificateThumbprint -ApplicationId $ApplicationID -TenantId $TenantId
$ClientSecret = ""
$ApplicationID = ""
$TenantID = ""
$graphtokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $ApplicationID
Client_Secret = $ClientSecret
}
@ChrFrohn
ChrFrohn / SetHolidayDate.ps1
Created May 1, 2022 10:30
Blog - Add new dates to Teams holidays using PowerShell
$HolidayID = Get-CsOnlineSchedule -Id "e48d56a7-461a-46b5-962c-196f6e85145d"
$HolidayID.FixedSchedule.DateTimeRanges += New-CsOnlineDateTimeRange -Start "05/06/2022" -End "06/06/2022"
Set-CsOnlineSchedule -Instance $HolidayID -Verbose
@ChrFrohn
ChrFrohn / CreateCertForAppReg.ps1
Last active September 22, 2022 18:06
CreateCertForAppReg.ps1
$CN = "MyAppReg" #Name of your cert.
$cert=New-SelfSignedCertificate -Subject "CN=$CN" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature -NotAfter (Get-Date).AddYears(5)
#Thumbprint - Make note of this
$Thumbprint = $Cert.Thumbprint
#Export cert. to download folder - FilePath can be changed to your linking
Get-ChildItem Cert:\CurrentUser\my\$Thumbprint | Export-Certificate -FilePath $env:USERPROFILE\Downloads\AppRegCert.cer
Write-Output "$Thumbprint <- Copy/paste this (save it)"
@ChrFrohn
ChrFrohn / InstallMSGraph.ps1
Last active April 23, 2022 12:02
InstallMSGraph.ps1
#Installs the Microsoft Graph PowerShell module - Remeber to start PowerShell as admin to be able to install.
Install-Module -Name Microsoft.Graph -verbose
@ChrFrohn
ChrFrohn / ConnectToMSGrahphWithCert.ps1
Last active April 23, 2022 12:02
ConnectToMSGrahphWithCert.ps1
$AppID = ""
$TenantID = ""
$Thumbprint = ""
Connect-MgGraph -ClientId $AppID -TenantId $TenantID -CertificateThumbprint $Thumbprint
@ChrFrohn
ChrFrohn / GetTeamsMeetingIDUsingJoinURL.ps1
Last active April 3, 2022 09:36
Get Microsoft Teams meeting ID from JoinURL to be used in PowerShell with MSGraph
#This code below will provide with you with the ID of a Teams meeting using the Join URL - The Join URL can be found in a Teams Meeting invitation
#This can be used in Connection to Get-MgUserOnlineMeeting & Get-MgUserOnlineMeetingAttendanceReport
Connect-MgGraph #Choose a method (Dealers choice)
$UserId = "" #Can be found on the user object page in AzureAD (one of many ways)
JoinURL = "" #Right click "Join Teams Meeting" in the meeting invite and paste in here
$decodedUrl = [System.Web.HttpUtility]::UrlDecode($JoinUrl) #This to get rid of "%20" etc in the url