Skip to content

Instantly share code, notes, and snippets.

View mavaddat's full-sized avatar
🏠
Working from home

Mavaddat Javid mavaddat

🏠
Working from home
View GitHub Profile
@mavaddat
mavaddat / htmlImagesToBaseSixtyFour.ps1
Created August 8, 2023 16:24
Convert all images to base64
$md = <# PATH TO MARKDOWN FILE #>
$images = Select-String -Pattern "(?<=!\[[^\(]+\()[^\)]+(?=\))" -Path $md | ForEach-Object { $_.Matches.Value }
$html = <# PATH TO HTML FILE #>
$images = Select-String -Pattern "(?<=src=`")[^`"]+(?=\))" -Path $html | ForEach-Object { $_.Matches.Value }
$imagesBase64 = [string[]]::new($images.Count)
foreach($image in $images){
try {
# $filehandle = [System.IO.File]::Open((Join-Path -Path (Split-Path -Path $md -Parent) -ChildPath $image),[System.IO.FileMode]::Open)
$filehandle = [System.IO.File]::Open($image,[System.IO.FileMode]::Open)
$bytes = [byte[]]::new($filehandle.Length)
@mavaddat
mavaddat / oneDriveTrustedZones.ps1
Last active August 4, 2023 19:55
Set OneDrive and SharePoint trusted zones
#Requires -RunAsAdministrator
$zones = "onedrive.com", "*.onedrive.com", "onedrive.live.com", "login.live.com", "g.live.com", "spoprod-a.akamaihd.net", "*.mesh.com", "p.sfx.ms", "oneclient.sfx.ms", "*.microsoft.com", "fabric.io", "*.crashlytics.com", "vortex.data.microsoft.com", "posarprodcssservice.accesscontrol.windows.net", "redemptionservices.accesscontrol.windows.net", "token.cp.microsoft.com/", "tokensit.cp.microsoft-tst.com/", "*.office.com", "*.officeapps.live.com", "*.aria.microsoft.com", "*.mobileengagement.windows.net", "*.branch.io", "*.adjust.com", "*.servicebus.windows.net", "vas.samsungapps.com", "odc.officeapps.live.com", "login.windows.net", "login.microsoftonline.com", "*.files.1drv.com", "*.onedrive.live.com", "*.*.onedrive.live.com", "storage.live.com", "*.storage.live.com", "*.*.storage.live.com", "*.groups.office.live.com", "*.groups.photos.live.com", "*.groups.skydrive.live.com", "favorites.live.com", "oauth.live.com", "photos.live.com", "skydrive.live.com", "api.live.net", "apis.live.
@mavaddat
mavaddat / reverseVars.ps1
Last active July 10, 2023 07:16
Reverse resolve %PATH% paths using available environment variables
# Create a list of the environment variables sorted by length
$envs = Get-ChildItem -Path Env:\ | ForEach-Object {
[pscustomobject]@{
Length = $_.Value.Length
Name = $_.Name
Value = $_.Value
}
} | Sort-Object -Descending -Property Length
# Replace the environment variables in the user path with the variable name
$userPath = [System.Environment]::GetEnvironmentVariable('PATH',[System.EnvironmentVariableTarget]::User) -split [System.IO.Path]::PathSeparator
@mavaddat
mavaddat / setupCerts.ps1
Last active December 2, 2025 21:31
Set up CA Cert bundles for all toolsets (Python, AWS, Git, NodeJs) in Windows using PowerShell Core. Answer on Stackoverflow question: https://stackoverflow.com/questions/51925384/unable-to-get-local-issuer-certificate-when-using-requests/76397035#76397035
#Requires -Version 6.0
#Requires -PSEdition Core
<#
.SYNOPSIS
Sets up Certificate Authority (CA) certificate bundles for various toolsets in Windows using PowerShell Core.
.DESCRIPTION
The Set-CaCertsBundles cmdlet is used to collect and set up CA certificates for various toolsets such as Python, AWS, Git, and NodeJs. It collects certificates from the local machine or current user store and configures environment variables for multiple toolsets to use these certificates. Optionally, it can create separate PEM files for NodeJs and import certificates into Windows Subsystem for Linux (WSL).
.PARAMETER Target
@mavaddat
mavaddat / updateModules.ps1
Created June 6, 2023 00:18
Update all out-of-date PowerShell modules using this one-liner.
Get-Module | Where-Object { $null -ne ($remoteVer = Find-Module -Name $_.Name -AllowPrerelease -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Version -ErrorAction SilentlyContinue) -and $_.Version -ne $remoteVer } | ForEach-Object { [pscustomobject]@{ Name = $_.Name; RemoteVer = $remoteVer; ThisVer = $_.Version } | Format-Table; Update-Module -Name $_.Name -AllowPrerelease -Verbose }
@mavaddat
mavaddat / setPythonRequestsCaBundle.ps1
Last active April 25, 2024 08:56
Setting Python REQUESTS_CA_BUNDLE for Windows using all the available certificates on the machine. Answer to this Stackoverflow question: https://stackoverflow.com/questions/51925384/unable-to-get-local-issuer-certificate-when-using-requests-in-python
#Requires -Version 6.0
# Allocate a temporary directory for receiving the certificates
$tmpCertsDir = New-Item -Path "$env:TEMP" -Name "Certs$(Get-Date -Format FileDateTimeUniversal)" -ItemType Directory -Force
# Collect the certs from the local machine
$certs = Get-ChildItem -Path Cert:\ -Recurse | Where-Object -FilterScript { $_.Thumbprint }
# This will contain the paths to the resulting PEM files
$pemPaths = [string[]]::new($certs.Count)
@mavaddat
mavaddat / addCertsToKeystores.ps1
Last active March 1, 2024 22:45
PowerShell script to add all Windows Certificates to the Java keystore for all visible JDK paths. Answer to StackOverflow question here: https://stackoverflow.com/questions/14532383/pem-file-from-microsoft-serialized-store-sst-files
#Requires -Version 6.0
#Requires -RunAsAdministrator
$jdkPaths = Get-Command -Name java -All | Where-Object -FilterScript { Test-Path -Path (Join-Path -Path ($_ | Split-Path -Parent) -ChildPath 'keytool.exe') } | Select-Object -ExpandProperty Path | Split-Path -Parent | Sort-Object -Unique
[array]$jdkPaths += Resolve-Path -Path "c:\Users\B0649033\.vscode*\extensions\redhat.java-*\jre\*\bin" | Select-Object -ExpandProperty Path
# Calculate existing certs first
$certBag = [System.Collections.Concurrent.ConcurrentBag[PSCustomObject]]::new()
$jdkPaths | ForEach-Object -Parallel {
# Parallel work for each JDK, since their respective stores do not conflict
$certBag = $using:certBag
@mavaddat
mavaddat / Part1-ConvertTo-ClassDefinition.ps1
Created May 30, 2023 13:35 — forked from thedavecarroll/Part1-ConvertTo-ClassDefinition.ps1
Creating a Class Definition from an Existing Object - Ironscripter Challenge
#Requires -Version 5.1
function ConvertTo-ClassDefinition {
param(
[Parameter(Position = 0, Mandatory, ValueFromPipeline)]
[object]$Object,
[ValidateNotNullOrEmpty()]
[string]$ClassName,
@mavaddat
mavaddat / grantSymLinkRights.ps1
Last active May 28, 2023 19:37
Grant a user Symbolic Links rights on Windows machines with PowerShell
#Requires -Version 3.0
function Add-SymLinkPermissions {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string]
$UserAccount = $env:USERNAME
)
Write-Host 'Checking SymLink permissions...'
$sidstr = $null
@mavaddat
mavaddat / bulkAddCerts.ps1
Last active May 9, 2023 13:23
Add certs to certstore Java using keytool.exe
Add-Type -Assembly PresentationCore
<# load ConvertTo-Slug from Gist #> Invoke-Expression (New-Object -TypeName System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/mavaddat/0bbed730a4c10a066d75894a7611d730/raw/4a37c2ec4f0d33ff2bbb1a224b0b901063dce871/slugify.ps1') # Imports Function ConvertTo-Slug
# Copy files to the clipboard in Windows explorer.exe
foreach ($crt in [System.Windows.Clipboard]::GetFileDropList())
{
$crt = $crt | Get-Item
$slug = $crt.Name | ConvertTo-Slug
if (-not (.\keytool.exe -list -alias $slug -cacerts -storepass changeit 2>&1 | Out-String | Select-String -Pattern "keytool error: java.lang.Exception: Alias <$slug> does not exist" -SimpleMatch))
{
.\keytool.exe -delete -cacerts -storepass changeit -alias $slug