Skip to content

Instantly share code, notes, and snippets.

View diecknet's full-sized avatar
👋

Andreas Dieckmann diecknet

👋
View GitHub Profile
# ACHTUNG! Das funktioniert nur, wenn das Company Attribut bei euren E-Mail Empfängern richtig gesetzt ist.
# Falls das Company Attribut leer ist, oder ein anderer Wert drin ist, müsst ihr einen anderen Filter verwenden.
# Oder das Attribut bei den Usern entsprechend setzen.
$CompanyName = "Demotenant"
New-DynamicDistributionGroup -Name "Alle-$($CompanyName)-Empfänger" -RecipientFilter "company -like '$($CompanyName)*'"
@diecknet
diecknet / HideReboot.reg
Created June 29, 2023 17:19
Hide Restart Button (Windows)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\Start\HideRestart]
"value"=dword:00000001
@diecknet
diecknet / Beispiel1.ps1
Created June 13, 2023 12:22
PowerShell Scopes Beispiele
# Script: Beispiel1.ps1
Write-Host '$a='$a
$a = "moin"
Write-Host '$a='$a
@diecknet
diecknet / Switch-Cmdlet.ps1
Created May 20, 2023 10:57
PowerShell Switch Beispiel
switch(Get-Date) {
# $PSItem ist übrigens das gleiche wie $_
{$PSItem.Year -gt 2022} {
"Es ist nach 2022"
break
}
default {
"Es ist vor 2023"
}
}
@diecknet
diecknet / Get-MachineSID.ps1
Last active April 21, 2023 07:49 — forked from IISResetMe/Get-MachineSID.ps1
PsGetSid local machine SID implementation in PowerShell
function Get-MachineSID {
# Going for the local SID by finding a local account and removing its Relative ID (RID)
$LocalAccountSID = Get-WmiObject -Query "SELECT SID FROM Win32_UserAccount WHERE LocalAccount = 'True'" |Select-Object -First 1 -ExpandProperty SID
$MachineSID = $LocalAccountSID -replace '-[^-]+$'
return $MachineSID
}
@diecknet
diecknet / Hashtable-Access-Performance-Test.ps1
Created October 27, 2022 12:40
PowerShell Hashtable Performance Tests
<#
Hashtable Access Performance Test
Settings:
$maxentries = Number of entries to put into the hashtable
$iterations = Number of access test per method
#>
$maxentries = 100000
$iterations = 5000
$meineHashtable = @{}
@diecknet
diecknet / Convert-SPOTimezoneToString.ps1
Created July 9, 2021 15:46
Sharepoint Online Timezone of a Site
function Convert-SPOTimezoneToString(
# ID of a SPO Timezone
[int]$ID
) {
<#
.SYNOPSIS
Convert a Sharepoint Online Time zone ID to a human readable string.
.NOTES
By Andreas Dieckmann - https://diecknet.de
@diecknet
diecknet / ActiveDirectory-Snippets.ps1
Created July 6, 2021 14:12
Windows Server Active Directory - Snippets
########################################################################################
# Add DNS Host A entry with PowerShell
# Forward / Host A
Add-DnsServerResourceRecordA -Name "test123" -ZoneName "myzone.local" -IPv4Address "10.0.0.1" -ComputerName mydnsserver
# Add PTR:
Add-DnsServerResourceRecordPtr -ZoneName 00.10.in-addr.arpa -Name 1.0 -PtrDomainName myhost.myzone.local -ComputerName mydnsserver
########################################################################################
@diecknet
diecknet / Copy2Clipboard.ps1
Created July 6, 2021 06:41
Copy last PowerShell command into clipboard
<#
I initially used this code:
history | Select-Object -Last 1 -ExpandProperty CommandLine | clip
But recently found this shorter version at https://powershellmagazine.com/post/2012-11-06-pstip-send-the-last-command-executed-to-clipboard/
#>
(Get-History)[-1].commandline | clip
@diecknet
diecknet / Apply-DNS-Workaround-CVE-2020-1350.ps1
Created July 15, 2020 10:34
Apply CVE-2020-1350 (SIG-RED) Workaround for Windows DC/DNS with PowerShell
<# by diecknet
# This script is mostly based on code by reddit users /u/bernys and /u/Lanathell
# I added checks to see if DNS service is running again.
# Also see:
# - https://support.microsoft.com/en-us/help/4569509/windows-dns-server-remote-code-execution-vulnerability
# - https://www.reddit.com/r/sysadmin/comments/hr5dfe/keep_your_eyes_out_for_a_critical/
#>
Import-Module ActiveDirectory
$AllDomainControllers = (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ }