Skip to content

Instantly share code, notes, and snippets.

View XPlantefeve's full-sized avatar

Xavier Plantefève XPlantefeve

View GitHub Profile
@XPlantefeve
XPlantefeve / filter_to_ldapfilter.ps1
Last active January 24, 2023 09:55
getting Active Directory info through ADSI
# Quick and very dirty PS filter to LDAP filters translation
function Format-LdapEscaped ($string,[switch]$wildcard) {
Switch -Regex ($string.Trim()) {
'^"(?<str>.*)"$' { $string = $Matches.str -replace '`"','"' }
"^'(?<str>.*)'$" { $string = $Matches.str -replace "''","'" }
}
$string = $string -replace '\\5c','\'
$string = $string -replace '\\00','NUL'
@XPlantefeve
XPlantefeve / WinHttpProxySettings.ps1
Last active July 16, 2022 17:14
netsh winhttp * proxy, but in PowerShell
# Quick & dirty. Basic error checking. It works where I needed it.
#
# Documentation used:
# - ProcMon
# - https://securelink.be/blog/windows-proxy-settings-explained/
# - https://docs.microsoft.com/en-us/windows/desktop/api/Winhttp/ns-winhttp-__unnamed_struct_3
# - https://github.com/vbfox/proxyconf/blob/master/README.md
# - https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/managing-bit-flags-part-1
# - https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_enum
#
@XPlantefeve
XPlantefeve / LICENSE.txt
Last active April 12, 2022 10:02
Powershell Gist management CMDlets
MIT License
Copyright (c) 2016 Xavier Plantefeve
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
# (very) quick and (very) dirty bencoding converter.
# I actually did not now what bencoding was and reverse engineered the few
# files I needed information about.
param(
[Parameter(Mandatory)]
[string[]]$Path
)
function vo ($hash) {
function Get-HumanReadableSize {
<#
.SYNOPSIS
Outputs a human readable version of a file size
.DESCRIPTION
This function rounds the value of the given file size to the nearest relevant
multiplier prefix (Gb, Mb, or Kb)
.INPUTS
long
.OUTPUTS
<#PSScriptInfo
.VERSION 1.0
.GUID 021fb1d9-6c04-4bea-983b-92e03d14963d
.AUTHOR Xavier Plantefeve
.COPYRIGHT 2020 Xavier Plantefeve
.TAGS ActiveDirectory,Password
.LICENSEURI https://opensource.org/licenses/MIT
.PROJECTURI https://gist.github.com/XPlantefeve/9b1e987baf1024149edad58bb88490b2
.EXTERNALMODULEDEPENDENCIES ActiveDirectory
#>
@XPlantefeve
XPlantefeve / Convert-CSVtoXLS.ps1
Last active September 17, 2019 20:14
CSV to XLS Powershell conversion
#requires -version 4.0
Function Convert-CSVtoXLS {
<#
.SYNOPSIS
This function converts a CSV file to an Excel workbook.
.DESCRIPTION
Convert-CSVtoXLS converts a csv file to a Excel workbook.
The first line of the CSV file is turned into a filtering header.
Excel must be installed on the computer.
@XPlantefeve
XPlantefeve / restoreOVHCloudArchive
Last active September 4, 2019 09:44
Restore files from OVH Cloud Archive
#!/bin/bash
dirname=$(dirname $0)
basename=$(basename $0)
conffile="${basename%.*}.conf"
if [ -f "$dirname/$conffile" ]
then
conffile="$dirname/$conffile"
. "$conffile"
function Get-FolderSizeRC($Path) {
if ( robocopy $Path c:\dummy /e /r:0 /w:0 /b /BYTES /nfl /ndl /np /njh /l | ? { $_ -match 'Bytes :\s*(?<size>\S+)' } ) { return [int64]$Matches.size }
}
function Get-FolderSizePS($Path) {
return ( ls -Recurse -Path $Path -Force | measure -Property length -Sum ) | select -ExpandProperty Sum
}
function test($Path) {
Write-Host -Object "Testing $Path" -ForegroundColor Cyan
@XPlantefeve
XPlantefeve / Do-Something.ps1
Last active February 14, 2019 09:17
Do-Something, the lazy typist way
# Laziness is a great gift
# Every function will have the exact same definition, so we won't bother
# copypasting.
$FunctionBody = {
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[object[]]$inputObject
)