Skip to content

Instantly share code, notes, and snippets.

View RylandDeGregory's full-sized avatar
🎯
Focusing

Ryland RylandDeGregory

🎯
Focusing
View GitHub Profile
@RylandDeGregory
RylandDeGregory / New-EventHubEvent.ps1
Created March 21, 2023 15:40
Add custom event to Azure Event Hub using PowerShell
[Reflection.Assembly]::LoadWithPartialName('System.Web') | Out-Null
$HMAC = New-Object System.Security.Cryptography.HMACSHA256
$EventHubsNamespace = ''
$EventHubName = ''
$EventHubEndpoint = "$EventHubsNamespace.servicebus.windows.net/$EventHubName"
$AccessPolicyName = 'RootManageSharedAccessKey'
$AccessPolicyKey = ''
$SASExpirationTime = ([DateTimeOffset]::Now.ToUnixTimeSeconds()) + 3000
@RylandDeGregory
RylandDeGregory / README.md
Created February 22, 2023 02:22
Embed PDF in Hugo post using Adobe Document Cloud API.

Setup

Get Adobe Document Cloud API key

Adobe Document Cloud PDF Embed API

Add shortcode layout to project

Add embed-pdf.html to the /layouts/shortcodes directory of your Hugo project.

@RylandDeGregory
RylandDeGregory / Remove-SpaceFromNegativeDecimal.ps1
Created February 3, 2023 21:32
Remove whitespace from negative decimal numbers using regex.
@(
'- 23.45'
'- 23.45'
'- 23.4'
'- 2.45'
) | ForEach-Object { $_ -replace '(-\s{1,})(\d{1,}\.\d{1,})', '-$2' }
@RylandDeGregory
RylandDeGregory / Get-DateArray.ps1
Created January 23, 2023 21:21
Generate a string array of all dates between a start and end date
$Date = Get-Date -Date '2022-01-01'
$EndDate = Get-Date -Date '2022-03-31'
$DateArray = do {
$Date.ToString('yyyy-MM-dd')
$Date = $Date.AddDays(1)
} until ($Date -gt $EndDate)
@RylandDeGregory
RylandDeGregory / Get-AzTableAllRows.ps1
Created December 23, 2022 16:10
Get all records (including pagination) from an Azure Storage Table using the Rest API
$TableRecords = @()
$StorageAccount = ''
$Table = ''
Connect-AzAccount
$AZStorageToken = Get-AzAccessToken -ResourceUrl 'https://storage.azure.com'
$AzTableHeaders = @{
Authorization = "$($AzStorageToken.Type) $($AzStorageToken.Token)"
Accept = 'application/json;odata=nometadata'
'x-ms-version' = '2020-08-04'
@RylandDeGregory
RylandDeGregory / Remove-GitBranches.ps1
Last active December 29, 2022 16:42
Remove multiple git branches by pattern using PowerShell
# Define pattern to match
$BranchPattern = 'bugfix/*'
# Delete all branches matching the defined pattern
git branch | Where-Object { $_.Trim() -like $BranchPattern } | ForEach-Object { git branch -d $_.Trim() }
@RylandDeGregory
RylandDeGregory / Copy-KeyVaultSecrets.ps1
Last active September 6, 2022 14:25
Copy Azure Key Vault Secrets from one vault to another using PowerShell's ForEach-Object -Parallel
#requires -version 7
$SourceKV = ''
$DestinationKV = ''
$SecretHash = Get-AzKeyVaultSecret -VaultName $SourceKV | ForEach-Object -Parallel { $Val = Get-AzKeyVaultSecret -VaultName $using:SourceKV -SecretName $_.Name -AsPlainText; [PSCustomObject]@{ Name = $_.Name; Value = $Val } }
$SecretHash | ForEach-Object -Parallel { Set-AzKeyVaultSecret -VaultName $using:DestinationKV -SecretName $_.Name -SecretValue $(ConvertTo-SecureString -AsPlainText -Force -String $_.Value) }
@RylandDeGregory
RylandDeGregory / Send-MgGraphEmail.ps1
Created August 9, 2022 19:14
Send email using Microsoft Graph
# Uses the interactive authentication flow with a web browser
Connect-MgGraph -Scopes 'Mail.Send'
# Build email message object
$Message = @{
subject = 'Test'
toRecipients = @(@{
emailAddress = @{
address = '[email protected]'
}
@RylandDeGregory
RylandDeGregory / Export-SqlToCsv.ps1
Created May 23, 2022 13:32
Export all tables in a SQL Server Database to individual CSV files.
$ServerName = ''
$DatabaseName = ''
$Username = ''
$Password = ''
$QueryTables = 'SELECT name FROM sys.tables ORDER BY name'
$Tables = Invoke-Sqlcmd -ServerInstance $ServerName -Database $DatabaseName -Username $Username -Password $Password -Query $QueryTables | Select-Object -ExpandProperty name
New-Item -ItemType Directory -Name "$DatabaseName-Export" -Force | Out-Null
@RylandDeGregory
RylandDeGregory / Get-AzVMInventory.ps1
Created January 26, 2022 15:56
Export an inventory of Azure VMs across all accessible Subscriptions to a CSV
Connect-AzAccount
foreach ($Subscription in $(Get-AzSubscription)) {
Get-AZVM | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
ResourceGroupName = $_.ResourceGroupName
Subscription = $Subscription.Name
Location = $_.Location
IPAddress = (Get-AzNetworkInterface -Name $_.NetworkProfile.NetworkInterfaces.Id.Split('/')[-1]).IpConfigurations.PrivateIpAddress
OSType = $_.StorageProfile.OsDisk.OsType