Skip to content

Instantly share code, notes, and snippets.

View diecknet's full-sized avatar
👋

Andreas Dieckmann diecknet

👋
View GitHub Profile
<#
.SYNOPSIS
I used this to find inconsistent file/folder ACL for FSLogix Profile Container folders in Azure Files (Azure Storage). It's not perfect but did a good enough job. This script is highly specific for my use-case. Feel free to change it for your needs.
.DESCRIPTION
This script scans the specified folder for subfolders. It checks if the Owner of the subfolder has exactly "Modify, Synchronize" rights for the folder. It then checks if the subfolder-owner also has these rights for files inside that subfolder. If there is more than one (1) file in the subfolder, it throws a warning but continues.
.NOTES
@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 $_ }
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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