Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
JustinGrote / Get-MgServicePrincipalPermission.ps1
Created December 1, 2022 23:51
Get a list of application and delegated permissions for a service principal, similar to what the Azure Portal shows
View Get-MgServicePrincipalPermission.ps1
#requires -version 7
using namespace Microsoft.Graph.PowerShell.Models
using namespace System.Collections.Generic
function Get-MgServicePrincipalPermission {
param(
[Parameter(ParameterSetName='Id',ValueFromPipelineByPropertyName)][Alias('Id')][string]$ServicePrincipalId,
[Parameter(ParameterSetName='Object',ValueFromPipeline)][MicrosoftGraphServicePrincipal]$ServicePrincipal
)
begin {
@Fabaderheld
Fabaderheld / Set-AzAPIPermission.ps1
Last active July 7, 2022 18:32
Permissions Ids for Graph
View Set-AzAPIPermission.ps1
Get Permissions
# MS Graph Permissions
(Get-AzAdServicePrincipal -ApplicationId 00000003-0000-0000-c000-000000000000).AppRole | Select *
(Get-AzAdServicePrincipal -ApplicationId 00000003-0000-0000-c000-000000000000).Oauth2PermissionScope | Select *
# Azure AD Graph
(Get-AzAdServicePrincipal -ApplicationId 00000002-0000-0000-c000-000000000000).AppRole | Select *
(Get-AzAdServicePrincipal -ApplicationId 00000002-0000-0000-c000-000000000000).Oauth2PermissionScope | Select *
@JustinGrote
JustinGrote / Get-ParamBlock.ps1
Created July 7, 2022 05:20
Get a hashtable of the parameters in your param block, useful for splatting.
View Get-ParamBlock.ps1
using namespace system.collections.generic
function Get-ParamBlock ([String[]]$Name) {
[hashset[string]]$params = $PSCmdlet.MyInvocation.MyCommand.Parameters.Keys
$params.ExceptWith([string[]]([PSCmdlet]::CommonParameters + [PSCmdlet]::OptionalCommonParameters))
$result = @{}
if ($Name) {$params = $params -in $Name}
foreach ($name in $params) {
$result.$name = $PSCmdlet.GetVariableValue($name)
}
return $result
@JustinGrote
JustinGrote / Receive-Task.ps1
Last active September 21, 2022 21:05
"Await" one or more tasks in PowerShell in a cancellable manner (e.g. ctrl-c still works)
View Receive-Task.ps1
using namespace System.Threading.Tasks
using namespace System.Collections.Generic
filter Receive-Task {
#Wait on one or more tasks in a cancellable manner
[CmdletBinding()]
param(
[parameter(Mandatory, ValueFromPipeline)][Task]$Task,
#How long to wait before checking for a cancellation in milliseconds
[int]$WaitInterval = 500
)
@JustinGrote
JustinGrote / Trace-AICommand.ps1
Last active July 18, 2022 19:23
Report the results and performance of any scriptblock to Azure Application Insights
View Trace-AICommand.ps1
#requires -version 7
#You can load this script with $(iwr https://tinyurl.com/TraceAICommand | iex)
using namespace Microsoft.ApplicationInsights
using namespace Microsoft.ApplicationInsights.Extensibility
using namespace Microsoft.ApplicationInsights.DataContracts
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Net
#Reference: https://docs.microsoft.com/en-us/azure/azure-monitor/app/console
@timothywarner
timothywarner / warner-bicep-2022.md
Last active February 28, 2022 03:14
Azure Bicep Quick Start by Tim Warner (@TechTrainerTim)
View warner-bicep-2022.md
@BelRarr
BelRarr / list-expiring-app-registrations.ps1
Created January 10, 2022 14:27
Get the list of expired or soon-to-expire azure app registrations
View list-expiring-app-registrations.ps1
$daysToExpire = 30
$SoonToBeExpiredList = @()
$AlreadyExpiredList = @()
# Connect to AzureAD
Write-Output "Connecting to AzureAD..."
$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzureAD -TenantId $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint
@potatoqualitee
potatoqualitee / ZInstall-KBUpdate.ps1
Last active January 10, 2022 15:44
Installing KB Updates on Remote System, 5 day dev journal
View ZInstall-KBUpdate.ps1
# THIS HASN'T BEEN ADDED TO THE KBUPDATE REPO YET BUT WILL BE WHEN I GET A MOMENT
function Install-KbPatch {
<#
.SYNOPSIS
Installs KBs on local and remote servers on Windows-based systems
.DESCRIPTION
Installs KBs on local and remote servers on Windows-based systems
PowerShell 5.1 must be installed and enabled on the target machine and the target machine must be Windows-based
@Myrddraal
Myrddraal / Test-ChangesMadeInPath.ps1
Last active April 6, 2022 14:16
Skip infrastructure deployments if there are no changes to deploy (Azure Pipelines)
View Test-ChangesMadeInPath.ps1
[CmdletBinding()]
param (
$authorisation,
$pathFilter,
$collectionUri,
$project,
$buildId
)
$changesUrl = "$collectionUri/$project/_apis/build/builds/$buildId/changes?api-version=6.0"
@dfinke
dfinke / Open-GHWebEditor.ps1
Last active August 17, 2021 12:42
Opens the GitHub web editor on a repo
View Open-GHWebEditor.ps1
function Open-GHWebEditor {
<#
.SYNOPSIS
Opens the GitHub web editor on a repo.
.EXAMPLE
Open-GHWebEditor powerShell/powerShell
#>
param(
[Parameter(Mandatory)]