Skip to content

Instantly share code, notes, and snippets.

# 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 `
@WimObiwan
WimObiwan / ConvertTo-Dictionary.ps1
Created August 26, 2019 14:38
ConvertTo-Dictionary
function ConvertTo-Dictionary {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
$Collection,
[Parameter(Mandatory=$true)]
[string]$Key
@WimObiwan
WimObiwan / Get-WithProgress.ps1
Last active December 16, 2019 09:00
Get-WithProgress.ps1
function Get-WithProgress {
param(
[string] $Activity = 'Processing',
[int] $Loop = 0
)
# v1.0 Initial version
# v1.1 Only increase progress AFTER processing an item
# Collect the pipeline input ($Input) up front in an array,
# using @(...) to force enumeration.
@WimObiwan
WimObiwan / Check Sql Server file size limit.sql
Last active June 13, 2019 13:37
Check if database files are nearing the SQL Server (Express Edition) limits
-- To check if database files are nearing the SQL Server (Express Edition) limits
DECLARE @version varchar(32) = CONVERT(varchar(32), SERVERPROPERTY ('ProductVersion'));
SELECT @version, @@VERSION;
DECLARE @limit_GB float;
IF SERVERPROPERTY('EngineEdition') = 4 -- Express Edition
BEGIN
-- SQL Server Express Edition:
-- Up till SQL Server 2008, limit is 4 GB / file
WITH BackupsPerDatabase AS
(
SELECT
--CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server,
db.database_id,
bs.type,
MAX(bs.backup_finish_date) AS last_db_backup_date
FROM sys.databases db
LEFT OUTER JOIN msdb.dbo.backupset bs ON db.name = bs.database_name
INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id
<html>
<head>
<title>Autotask Login Proxy Page</title>
<script>
function loginForm() {
document.myform.submit();
}
</script>
</head>