From 27a8255ba495e6d17123a8745d3f5bbe678c106c Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Mon, 7 Oct 2024 13:51:06 +0200 Subject: [PATCH] initial commit --- README.md | 11 +++++++++++ cheats/ad | 18 ++++++++++++++++++ cheats/exchange | 14 ++++++++++++++ cheats/openssl | 14 ++++++++++++++ cheats/powershell | 8 ++++++++ cheats/robocopy | 2 ++ cheats/sqlite | 5 +++++ cheats/windows | 6 ++++++ cheats/wsl | 2 ++ 9 files changed, 80 insertions(+) create mode 100644 README.md create mode 100644 cheats/ad create mode 100644 cheats/exchange create mode 100644 cheats/openssl create mode 100644 cheats/powershell create mode 100644 cheats/robocopy create mode 100644 cheats/sqlite create mode 100644 cheats/windows create mode 100644 cheats/wsl diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f73fde --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Collection of command line cheats + +## Shell integration + +``` +function cheat() { + bat -l md -p ~/cheat/cheats/"$1" --color always --theme="Dracula" | tr -d '`' +} +# autocompletion for zsh +compdef '_files -W "/home/panki/cheat"' cheat +``` diff --git a/cheats/ad b/cheats/ad new file mode 100644 index 0000000..9cd5665 --- /dev/null +++ b/cheats/ad @@ -0,0 +1,18 @@ +# global catalog port +`-server dc01.contoso.com:3268` + +# set extension attr +`Set-ADUser -replace @{extensionAttribute15='f'}` + +# pw never expires +`Get-AdUser -filter { passwordNeverExpires -eq $true -and enabled -eq $true } | Select Name, DistinguishedName` + +# get user by SID +`get-aduser -Identity "S-1-5-21-" -server dc01.contoso.com:3268` + +# force pw reset +`get-aduser -filter * -SearchBase 'OU=Users,DC=Contoso,DC=com' | set-aduser -ChangePasswordAtLogon $true` + +# submit CSR to CA +`certreq -submit -attrib "CertificateTemplate:Webserver Version3" docs_req.req` + diff --git a/cheats/exchange b/cheats/exchange new file mode 100644 index 0000000..cd37212 --- /dev/null +++ b/cheats/exchange @@ -0,0 +1,14 @@ +# Restore deleted resource +## Find mailbox ID +`Get-MailboxDatabase | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {($_.DisplayName -eq "Room 01.03") -and ($_.DisconnectReason -eq "SoftDeleted" -or "Disabled")} | Format-List DisplayName,DisconnectReason,DisconnectDate,MailboxGuid` +## Create new resource, then restore: +`New-MailboxRestoreRequest -SourceStoreMailbox 369c6ce9-301d-41af-b4cf-cca87d679756 -SourceDatabase MailDB07 -TargetMailbox MULRaumG6.03.410 -AllowLegacyDNMismatch` + +# give group permission on mailbox "finance1" +`add-mailboxpermission -Identity finance1 -user CONTOSO\Accounting -AccessRights 'FullAccess'` + +# set external mail address +`Enable-MailUser -Identity FreemanG -ExternalEmailAddress gordon.freeman@contoso.com` + +# add access to calendar +`Add-MailboxFolderPermission -Identity Maintenance@contoso.com:\Calendar -User gordon.freeman@contoso.com -AccessRights Editor` diff --git a/cheats/openssl b/cheats/openssl new file mode 100644 index 0000000..61fb7a4 --- /dev/null +++ b/cheats/openssl @@ -0,0 +1,14 @@ +# show cert info +`openssl x509 -noout -text -in cert.pem` + +# import pkcs12 into jks +`keytool -importkeystore -srckeystore mypfxfile.pfx -srcstoretype pkcs12 -destkeystore clientcert.jks -deststoretype JKS` + +# pkcs12/pfx to pem/crt + key +## export key +`openssl pkcs12 -in filename.pfx -nocerts -out key.pem` +## remove passphrase +`openssl rsa -in key.pem -out server.key` +## export cert +`openssl pkcs12 -in filename.pfx -clcerts -nokeys -out cert.pem` + diff --git a/cheats/powershell b/cheats/powershell new file mode 100644 index 0000000..8165e5e --- /dev/null +++ b/cheats/powershell @@ -0,0 +1,8 @@ +# Replace column names +`| Select-Object @{N='samAccountName'; E={$_.InputObject}},@{N='Action'; E={$_.SideIndicator}}` + +# convert timestamp +`Select @{N='LastLogon'; E={[DateTime]::FromFileTime($_.LastLogon)}}` + +# check error +`$Error[0] | fl *` diff --git a/cheats/robocopy b/cheats/robocopy new file mode 100644 index 0000000..f680ac6 --- /dev/null +++ b/cheats/robocopy @@ -0,0 +1,2 @@ +# Compare folder contents recursively (no move) +`robocopy source dest /l /e /fp /np /njh /ndl` diff --git a/cheats/sqlite b/cheats/sqlite new file mode 100644 index 0000000..bac51d4 --- /dev/null +++ b/cheats/sqlite @@ -0,0 +1,5 @@ +# list all tables +`.tables` + +# select all +`select * from ConfigUser` diff --git a/cheats/windows b/cheats/windows new file mode 100644 index 0000000..381f33d --- /dev/null +++ b/cheats/windows @@ -0,0 +1,6 @@ +# portforward windows localhost to wsl +`netsh interface portproxy add v4tov4 listenport=1080 listenaddress=127.0.0.1 connectport=1080 connectaddress=$(hostname -I)` + +# update computer account group membership (without reboot) +`klist -lh 0 -li 0x3e7 purge` +`gpupdate` diff --git a/cheats/wsl b/cheats/wsl new file mode 100644 index 0000000..21a8faa --- /dev/null +++ b/cheats/wsl @@ -0,0 +1,2 @@ +# mount admin share +`sudo --preserve-env=HOME mount -t cifs -o username=freemang,domain=CONTOSO //citadel.contoso.com/c$ /mnt/srv`