Skip to content

Instantly share code, notes, and snippets.

View JeffBrownTech's full-sized avatar

Jeff Brown JeffBrownTech

View GitHub Profile
@JeffBrownTech
JeffBrownTech / AzFunc-PSTNUsageRecords.ps1
Last active January 19, 2021 04:53
Code Added to TeamsCallCommunicationApi for an Azure Function
# Create credential object and get access token
$secureClientSecret = ConvertTo-SecureString -String $env:ClientSecret -AsPlainText -Force
$graphApiCreds = New-Object System.Management.Automation.PSCredential($env:ClientId, $secureClientSecret)
$accessToken = Get-GraphApiAccessToken -Credential $graphApiCreds -TenantId $env:TenantId
# Get previous 2 day of records
$pstnRecords = Get-TeamsPstnCalls -Days 2 -AccessToken $accessToken
$pstnRecordCount = $pstnRecords.Count
$counter = 1
Write-Information -MessageData "Found $pstnRecordCount records"
@JeffBrownTech
JeffBrownTech / PSSomethingModule.Tests.ps1
Created June 25, 2020 01:00
Pester v5 Test Script for PSSomethingModule
Import-Module .\PSSomethingModule.psm1 -Force
Describe "Get-Something" {
Context "when parameter ThingToGet is not used" {
It "should return 'I got something!'" {
Get-Something | Should -Be 'I got something!'
}
It "should be a string" {
Get-Something | Should -BeOfType System.String
@JeffBrownTech
JeffBrownTech / TeamsAndGraphApi.ps1
Created April 24, 2020 00:13
Create M365 Group, Team, and Channel in PowerShell Using Microsoft Graph API
# Configure app registration and tenant information
$env:graphApiDemoAppId = "12345678-abcd-efgh-jklm-123456789abc" # Replace with your Azure AD app id
$env:graphApiDemoAppSecret = "1234567890asdfjk;l54321" # Replace with your Azure AD app secret
$env:tenantId = "12345678-abcd-efgh-ijkl-987654321wxyz" # Replace with your Azure AD tenant ID
$oauthUri = "https://login.microsoftonline.com/$env:tenantId/oauth2/v2.0/token"
# Create token request body
$tokenBody = @{
client_id = $env:graphApiDemoAppId
@JeffBrownTech
JeffBrownTech / CreateChannelUsingGraphApi.ps1
Created April 23, 2020 23:48
Create Graph API request to create a Teams channel
$channelBody =
'{
"displayName": "Channel from Graph API",
"description": "Demo how to make a channel using graph api"
}'
$newChannel = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/teams/$($newTeam.id)/channels" -Method POST -Headers $headers -Body $channelBody
@JeffBrownTech
JeffBrownTech / CreateTeamUsingGraphAPI.ps1
Created April 23, 2020 12:37
Create Graph API Request to Turn M365 Group into a Team
# Create the team request body
$teamBody =
'{
"memberSettings": {
"allowCreateUpdateChannels": true,
"allowDeleteChannels": true,
"allowAddRemoveApps": true,
"allowCreateUpdateRemoveTabs": true,
"allowCreateUpdateRemoveConnectors": true
},
@JeffBrownTech
JeffBrownTech / CreateGroupUsingGraphAPI.ps1
Last active April 24, 2020 00:20
Create Graph API Request to make an M365 Group
# Create group request body
$groupBody =
'{
"displayName": "Team from Graph API Demo",
"mailNickname": "teamfromgraphapidemo",
"description": "Demo making a group from Graph API",
"owners@odata.bind": [
"https://graph.microsoft.com/v1.0/users/{id}" # Use object ID or UPN of user
],
"groupTypes": [
@JeffBrownTech
JeffBrownTech / CreateOAuthAccessToken.ps1
Last active April 23, 2020 12:35
Creating OAuth Token for Graph API
$env:graphApiDemoAppId = "12345678-abcd-efgh-jklm-123456789abc" # Replace with your Azure AD app id
$env:graphApiDemoAppSecret = "1234567890asdfjk;l54321" # Replace with your Azure AD app secret
$env:tenantId = "12345678-abcd-efgh-ijkl-987654321wxyz" # Replace with your Azure AD tenant ID
$oauthUri = "https://login.microsoftonline.com/$env:tenantId/oauth2/v2.0/token"
# Create token request body
$tokenBody = @{
client_id = $env:graphApiDemoAppId
client_secret = $env:graphApiDemoAppSecret
@JeffBrownTech
JeffBrownTech / PromptMethod-Graphical.ps1
Last active March 30, 2020 12:36
Creating a graphical prompt inside PowerShell using .NET Framework form-building features
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
function Remove-MyItem {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 1)]
[string]
$Path
)
@JeffBrownTech
JeffBrownTech / PromptMethod-dotNET.ps1
Created March 26, 2020 12:41
Create a PowerShell prompt using .NET classes
function Remove-MyItem {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 1)]
[string]
$Path
)
$item = Get-Item -Path $Path
@JeffBrownTech
JeffBrownTech / PromptMethod-Manual.ps1
Created March 26, 2020 12:36
Create prompt in PowerShell using 'manual' method
function Remove-MyItem {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 1)]
[string]
$Path
)
$item = Get-Item -Path $Path