Skip to content

Instantly share code, notes, and snippets.

View itpropro's full-sized avatar
🏠
Working from home

Jan-Henrik Damaschke itpropro

🏠
Working from home
View GitHub Profile
function Get-NtSecurityDescriptor {
param
(
[string]$SecurityDescriptor
)
$ntsecdesc = New-Object Byte[] ($SecurityDescriptor.Length)
for ($i = 0; $i -lt $SecurityDescriptor.Length ; $i += 2) {
$ntsecdesc.Set(($i/2),([Byte]::Parse($SecurityDescriptor.Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber)))
}
# When a document is created in D:\Test with the extension .rtf This script will print its name
Register-CimIndicationEvent -Query "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE
TargetInstance ISA 'CIM_DataFile' AND (TargetInstance.Drive='D:' AND TargetInstance.Path='\\Test\\' AND TargetInstance.Extension='rtf')" -Action {
Write-Host $($Event.SourceEventArgs.NewEvent.TargetInstance.Name)
}
[DscLocalConfigurationManager()]
Configuration PullClientV2 {
param(
[Parameter(Mandatory=$True)]
[String]$ConfigurationNames,
[Parameter(Mandatory=$True)]
[String]$Server
)
Settings
{
<Obj RefId="29">
<TN RefId="9">
<T>Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/ServerManager/ServerComponent_RemoteAccess</T>
<T>Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/ServerManager/MSFT_ServerManagerServerComponentDescriptor</T>
<T>Microsoft.Management.Infrastructure.CimInstance#ServerComponent_RemoteAccess</T>
<T>Microsoft.Management.Infrastructure.CimInstance#MSFT_ServerManagerServerComponentDescriptor</T>
<T>Microsoft.Management.Infrastructure.CimInstance</T>
<T>System.Object</T>
</TN>
<ToString>ServerComponent_RemoteAccess</ToString>
$xmlpath = 'C:\Temp\DeploymentConfigTemplate.xml'
$features = New-Object -TypeName System.Collections.ArrayList
[xml]$xml = Get-Content $xmlpath
$xml.Objs.Obj.LST.Obj | ForEach-Object {$null = $features.Add($_.GetElementsByTagName('ToString').'#text')}
for ($i = 0; $i -lt $features.Count; $i++)
{
$features[$i] = $features[$i].Substring($features[$i].IndexOf('_') + 1).Replace('_','-')
}
$features
function Get-AvailableComObjects {
$classesCom = ''
$classes = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SOFTWARE\\Classes').GetSubKeyNames()
[regex]::Matches($classes, '\w+\.\w+').Value | % {if ([Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWARE\\Classes\\$_\\CLSID")) {$classesCom += "$_`r`n"}}
$classesCom.Replace("`r`n",' ').Split(' ') | Select-Object -Unique
}
function convertto-cidr
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]$netmask
)
$cidr = ''
foreach ($segment in $netmask.split('.'))
function Set-WakeEnabled
{
<#
.SYNOPSIS
Set WoL on nic
Author: Jan-Henrik Damaschke (@jandamaschke)
License: BSD 3-Clause
Required Dependencies: None
@itpropro
itpropro / autohotkey_bruteforce.ahk
Created February 10, 2019 15:33
Example script, how to implement small (and of course slow) buteforce scripts with autohotkey
SendMode Input
!z::
loop 26 {
i := Asc("a") + A_Index - 1
loop 26 {
j := Asc("a") + A_Index - 1
loop 26 {
k := Asc("a") + A_Index - 1
l := Chr(i)
m := Chr(j)
@itpropro
itpropro / umlauts.ahk
Created February 10, 2019 15:35
Example shortcuts for german umlauts on en-us keyboards
SetTimer,UPDATEDSCRIPT,1000
UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
SplashTextOn,,,Script was updated,
Sleep,500
Reload
}