Skip to content

Instantly share code, notes, and snippets.

View gitfvb's full-sized avatar
👋

Florian von Bracht gitfvb

👋
View GitHub Profile
@gitfvb
gitfvb / rescue.txt
Created October 6, 2017 14:54
rescue files
# aus ct http://epaper.heise.de/download/archiv/d797d41f4c80/ct.16.06.160.pdf
# create image
sudo apt-get install gddrescue
lsblk -f -o +SIZE,MODEL
sudo ddrescue /dev/sdx image.img
cp image.img image.img.bak
# rescue files
@gitfvb
gitfvb / add_line_number.ps1
Last active November 14, 2017 09:25
powershell csv gists
Import-CSV SomeFile.csv | Select *,LINENUMBER | ForEach-Object -Begin { $Line = 1 } {
$_.LineNumber = $Line++
$_
} | Export-CSV SomeFile.csv
@gitfvb
gitfvb / save_json_response_as_csv.ps1
Last active December 1, 2017 17:41
powershell json restapi csv
# several commands via Invoke-RestMethod
$request = 'https://piwikdomain/index.php?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=JSON&token_auth=<token>'
$RestCall = Invoke-RestMethod -Uri $request
$RestCall | Export-Csv -Delimiter "`t" -Encoding "UTF8" -path whatever1.csv -NoTypeInformation
# single line with pipes
$request = 'https://piwikdomain/index.php?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=JSON&token_auth=<token>'
( Invoke-RestMethod -Uri $request ) | Select * | Export-Csv -Delimiter "`t" -Encoding "UTF8" -path whatever2.csv -NoTypeInformation
@gitfvb
gitfvb / mailingwork_getmailings.ps1
Last active October 25, 2019 16:12
calling mailingwork via powershell
[System.Uri]$endpoint = "https://login.mailingwork.de/webservice/webservice/json/"
$verb = 'getmailings'
$params = @{
username='<username>'
password='<password>'
}
$result = Invoke-RestMethod -Uri "$($endpoint)$($verb)" -Method POST -Body $params -Verbose
@gitfvb
gitfvb / delete duplicates from sqlite and shrink.ps1
Last active December 13, 2022 18:59
running multiple commands through sqlite command line via powershell
"DELETE FROM jobs WHERE rowid NOT IN (SELECT min(rowid) FROM jobs GROUP BY JobId)" | .\sqlite3.exe .\jobs2.sqlite
"VACUUM" | .\sqlite3.exe .\jobs2.sqlite
@gitfvb
gitfvb / profitbricks_nic_remote_desktop_rpd.ps1
Last active January 18, 2018 12:39
profitbricks handling through CLI / Powershell with interactive powershell tables for start/stop/remotedesktop
# create empty array for all server network interfaces
$server=@()
# run through every datacenter and append every single server to a list
( profitbricks datacenter list --json | ConvertFrom-JSON ) | ForEach {
# append data from the datacenter
$dataCenterId = $_.Id
$dataCenterName = $_.Name
$dataCenterLocation = $_.Location
@gitfvb
gitfvb / links.json
Last active October 29, 2018 16:46
Preparation for DSGVO/GDPR to save multiple website as screenshot (PNG) and html. This script can emulate a click on a button like "newsletter subscription" by giving a third (a class name) or fourth (a id) parameter. To get this powershell running, please download https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-windows.zip and p…
@gitfvb
gitfvb / use_other_locale.ps1
Created April 11, 2018 18:04
use another locale e.g. for outputting a date string
# cool function to create a date output in another locale
# SOURCE: https://stackoverflow.com/questions/2379514/powershell-formatting-values-in-another-culture
function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"),
[ScriptBlock]$script=(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"))
{
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
$OldUICulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture
try {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
@gitfvb
gitfvb / s3_profitbricks.ps1
Created April 13, 2018 10:09
S3 on profitbricks via powershell (work in progress, but works): Download, Upload, ListBuckets and ListFilesInBucket
<#########################
LINKS
#########################>
<#
resource: https://devops.profitbricks.com/api/s3/
https://gist.github.com/chrismdp/6c6b6c825b07f680e710
https://gist.github.com/tabolario/93f24c6feefe353e14bd
@gitfvb
gitfvb / read_all_in_once.ps1
Created April 24, 2018 09:30
access sqlite via ado.net driver in powershell
# Inspiration: https://www.pipperr.de/dokuwiki/doku.php?id=windows:powershell_oracle_db_abfragen
# https://docs.microsoft.com/de-de/dotnet/framework/data/adonet/retrieving-and-modifying-data
$assemblyFile = "C:\PathToDLL\System.Data.SQLite.dll" # download precompiled binaries for .net or "System.Data.SQLite"
$connString = 'Data Source="file.sqlite";Version=3;'
$sqlCommand = "Select * from households limit 100"
[Reflection.Assembly]::LoadFile($assemblyFile)