Skip to content

Instantly share code, notes, and snippets.

View gravejester's full-sized avatar

Øyvind Kallstad gravejester

View GitHub Profile
@gravejester
gravejester / Write-LogMessage.ps1
Created October 30, 2024 17:44
Write-LogMessage
function Write-LogMessage{
[CmdletBinding()]
param (
[Parameter()]
[string] $Message,
[Parameter()]
[string] $LogType = 'Info'
)
@gravejester
gravejester / Test-ExistInEnvPath.ps1
Last active November 1, 2024 12:38
Check if file exists in environment paths
function Test-ExistInEnvPath($fileName) {
$envPaths = ($env:Path -split ';') | Where-Object {$_ -ne ''}
$envPaths | ForEach-Object {
if (Test-Path -Path (Join-Path -Path $_ -ChildPath $fileName)) {
Write-Output $true
} else {
Write-Output $false
}
}
}
@gravejester
gravejester / Copy-FileWithStructure.ps1
Last active October 18, 2024 07:11
Function to copy a file while keeping the original folder structure (relative to the destination path)
function Copy-FileWithStructure($Path,$Destination) {
$fileObject = Get-Item -Path $Path
$pathParts = ($fileObject.Directory.ToString()).split([System.IO.Path]::DirectorySeparatorChar)
$newDestination = Join-Path -Path $Destination -ChildPath (($pathParts | Select-Object -Skip 1) -join([System.IO.Path]::DirectorySeparatorChar))
$script:newPath = $Destination
# Loop through and re-create the folder structure
foreach ($pathPart in ($pathParts | Select-Object -Skip 1)) {
$newPath = Join-Path -Path $newPath -ChildPath $pathPart
if (-not(Test-Path -Path $newPath)) {
@gravejester
gravejester / self-update.ps1
Created June 5, 2024 10:19
self-updating script
function New-Thread {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
[scriptblock] $Script,
# Timeout in seconds
[Parameter()]
[int] $TimeOut = 60
)
function Get-ADUserTokenGroups {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[Alias('u','User')]
[string] $ADUserName = $env:USERNAME
)
try {
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
DNS_NAME="some.domain.tld"
openssl s_client -connect ${DNS_NAME}:443 -servername ${DNS_NAME} 2>/dev/null </dev/null | openssl x509 -noout -dates -issuer -subject
function Get-CertInfoHttp {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory)]
[string] $URL,
[Parameter()]
[switch] $ReturnCertificate
)
function Get-CertInfoTcp {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory)]
[string] $ComputerName,
[Parameter(Position = 1)]
[int] $Port = 443,
[Parameter()]
#!/bin/bash
SP_NAME=$1
SP_PW=$2
SP_TENANT=$3
# Authenticate to Azure
if [ -z "$SP_NAME" ] || [ -z "$SP_PW" ] || [ -z "$SP_TENANT" ]
then
LOGIN_RESULT=$(az login)
@echo off
IF [%1]==[] (
IF [%2]==[] (
IF [%3]==[] (
az login
)
)
) ELSE (
az login --username %1 --password %2 --tenant %3 --service-principal
)