My miscancellous powershell stuff
Enable DFS-N-ABE, Access Based Enumeration, transfer the NTFS ACL settings if possible, and tick the "Set explicit view permissions on the DFS folder" which Microsoft Documentation says: "Not possible using Powershell". I needed it for a mass job, and dfsutil.exe failed in that environment due to complex active directory forest structure. So not much of a choice than to do it using Powershell.
Tools for mass converting JPEG/PNG (GIF commented out) to .JXL, but only keep the .JXL if the result is smaller and conversion went without errors.
Use NTFS compression as pure powershell method, without calling compact.exe. Side effect: Can handle unicode and long paths.
There are no WORKING Powershell scripts to calculate CRC16 Modbus. So I took an actually correct working C implementation and translated it to powershell.
It will show all properties of an object, with all sub-properties. Output looks like this for the example:
Simple script which resturns the process and all child processes of a given -StartPID. If none is given the current PID is used. If recursive-resistant (i.e. does not loop endless on -StartPID 0, which is its own parent/child)
Actually WORKING example how to send and receive from serial port with Powershell. Let alone sending and revieving BINARY data. In this case reading the current power and other data from a Growatt 600 MIC using an RS485-to-USB adapter. If your run it from Poertshell ISE it will output the values on screen. Else it will write it in a .CSV file using ";" as delimiter since, well, German Excel.
Rant: A lot of serial port examples on the internet are half, and Register-ObjectEvent works in PSIE and manually in shell, but NOT when used in script (most weird powershell bug so far). It is like those people never actually tried to implement it.
This activates detailled SMB1 and NTLM auditing/logging AND analyzes the eventlogs with appriopriate methods to get what needed. Requires at least Server 2012 with Powershell 5.1 and current updates. On subsequent runs it only analyzes the event logs when auditing/logging. Reports saved as .CSV on Desktop. Default delimiter is ";" for Germany, edit the script if you need it different.
Task scheduler -> import. For a daily report, expecially on busy domain controllers where the security log does not span several weeks.
This is a ping in pure powershell. I needed something "faster than Test-Netconnection". It sends, by default, four pings withing 800 ms, really only pings, and then gives up. You can change the TTL, Timeout and Retry settings with -TTL -TimeOut and -Retry.
Invert and/or transform image or picture color in powershell, the fast way. The examples I found for "Powershell Invert Image" or "DOTNET invert image" did it pixel by pixel. Which is VERY slow. So I dug around, found the much faster way to do it in DOTNET, added gamma correction since I needed it for my case, and used it in Powershell. And then "Well, why not publishing it, maybe others need it too?". Input can be either a filename or a [System.Drawing.Bitmap] which you just created in Powershell. Output is either a file you suply, or a [System.Drawing.Bitmap]
Example: Left part is the original, right part is the inverted darkened which is then set as my non-intrusive Windows background wallpaper.
Actually working (tested with PS 5.1 on Server 2022 and Windows 11) example for Wake On LAN in pure powershell. Skips unconfigured adapters and does a correct broadcast address calculation in contrast to many other examples I found on the net + works on IPv6 as well.
This is a very simple script to force the deduplication-corruption bug in nested-VM scenarios with Server 2022 and Server 2025 (Server 2019 is fine). Refer to this thread for more details: https://techcommunity.microsoft.com/t5/windows-server-insiders/nested-v-dedup-corruption-26100-1742-and-insider-26296-5001-and/m-p/4263322