Skip to content

Instantly share code, notes, and snippets.

@WimObiwan
WimObiwan / Select-GraphObject.ps1
Last active September 17, 2024 08:46
Select-GraphObject.ps1 to flatten objects returned by Microsoft Graph, Azure, ... Powershell cmdlets
#usage:
# Get-MgGroupMember -GroupId <someid> | `
# Select-GraphObject displayname, userprincipalname, mail, officelocation
#based on https://stackoverflow.com/questions/72384632/possible-to-pull-info-from-additionalproperties-dictionary-with-microsoft-graph
#with some changes to make it work
function Select-GraphObject {
[CmdletBinding(PositionalBinding = $false)]
param(
@WimObiwan
WimObiwan / WinDbg script.txt
Last active October 19, 2021 08:16
WinDbg troubleshoot deadlocks caused by WinForms STA-violations
* START EXE IN WINDBG
* Based on https://web.archive.org/web/20160223063851/http://blogs.msdn.com/b/dsui_team/archive/2012/10/31/debugging-windows-forms-application-hangs-during-systemevents.userpreferencechanged.aspx
sxe ld clrjit
g
.sympath srv*http://msdl.microsoft.com/download/symbols
.reload
.loadby sos.dll clr
function Get-AccessTokenClientCredentialsFlow {
param (
[string]$ClientId,
[string]$ClientSecret,
[string]$Audience
)
Add-Type -AssemblyName System.Web
$clientidEnc = [System.Web.HttpUtility]::UrlEncode($ClientId)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/11.0.0/css/fabric.min.css" />
<title>Microsoft Teams Tab</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
cat /var/log/auth.log /var/log/auth.log | grep 'authentication failure;' | sed 's/.*rhost=\([^ ]*\).*/\1/' | sort | uniq -c
# Example usage:
# . C:\temp\Test-EnduranceSqlConnection.ps1
# Test-EnduranceSqlConnection '192.168.253.127\Corflow' -Interval ([timespan]::FromSeconds(1))
function Test-Key {
[CmdletBinding()]
param (
[System.ConsoleKey]$Key
)
function Match([string]$x, [string]$y) {
if ($x.Length -ne $y.Length) { return '' }
$result = ''
@(0..($x.Length - 1)) | %{
if ($x[$_] -eq $y[$_]) {
$result += '*'
} elseif ($y.Contains($x[$_])) {
$result += '?'
} else {
$result += '.'
dir -Recurse -Filter *.cs | gc | %{ if ($_ -match '^.*(http(?:s)?\://[^/]*/).*$') { $Matches[1] } } | select -Unique
@WimObiwan
WimObiwan / Remove values from Zabbix.md
Created October 24, 2019 15:17
Remove values from Zabbix

On Zabbix server, connect to MariaDB by running:

mysql

And go to the correct database, e.g.:

@WimObiwan
WimObiwan / CleanupOldFiles.ps1
Last active August 29, 2019 11:58
CleanupOldFiles.ps1
$folder = 'C:\Temp\', $env:TEMP, '~/Downloads'
$threshold = (Get-Date).AddMonths(-1.0)
$ConfirmPreference = 'Low'
$oldFiles = $folder | Get-ChildItem -File -Recurse | ?{ $_.LastAccessTime -lt $threshold }
$oldFiles | Sort-Object -Property Length -Descending | Select -First 25 Length, FullName
$oldFiles | Measure-Object -Property Length -Sum -Maximum -Minimum -Average
$oldFiles | Remove-Item -Force -Confirm
$emptyFolders = $folder | Get-ChildItem -Directory -Recurse `