Skip to content

Instantly share code, notes, and snippets.

$conn = New-Object system.net.sockets.tcpclient($host, $port)
$stream = New-Object system.net.security.sslstream($conn.getstream(), $null, {
Write-Host $args[2].ChainElements[0].Certificate.Subject;
Write-Host "PolicyErrors: $($args[3])";
})
$result = $stream.authenticateasclient("chocolatey.org")
$conn.Close()
@newyear2006
newyear2006 / TestDatei.ps1
Last active January 2, 2016 05:29
Nochmal der Versuch eine Beschreibung hinzuzufügen
$conn = New-Object system.net.sockets.tcpclient($host, $port)
$stream = New-Object system.net.security.sslstream($conn.getstream(), $null, {
Write-Host $args[2].ChainElements[0].Certificate.Subject;
Write-Host "PolicyErrors: $($args[3])";
# Immer True zurückgeben, damit alle Zertifikate auch mit Fehler akzeptiert werden.
$true;
})
$result = $stream.authenticateasclient("chocolatey.org")
$conn.Close()
$SFTCode = @"
[DllImport("kernel32")] public static extern uint EnumSystemFirmwareTables (uint FirmwareTableProviderSignature, IntPtr pFirmwareTableBuffer, uint BufferSize);
[DllImport("kernel32")] public static extern uint GetSystemFirmwareTable (uint FirmwareTableProviderSignature, uint FimrwareTableID, IntPtr pFirmwareTableBuffer, uint BufferSize);
"@
$SFT = Add-Type -MemberDefinition $SFTCode -Name "SFTKlasse" -Language CSharp -UsingNamespace "System.Reflection", "System.Diagnostics", "System.Collections.Generic" -PassThru
# 0×41435049=ACPI ? https://github.com/michaelforney/coreboot/blob/master/src/include/cbmem.h
@newyear2006
newyear2006 / Format-Hex.PS1
Last active August 29, 2015 14:12
Format-Hex
# Format-Hex based on http://www.leeholmes.com/blog/2009/11/23/hex-dumper-in-powershell/
# Extended with additional parameters and fixed some formatting issues.
##############################################################################
##
## Format-Hex
##
## From Windows PowerShell Cookbook (O’Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
@newyear2006
newyear2006 / SMTPStartTLS.PS1
Created August 23, 2015 22:09
Beispiel wie man eine einfache Verbindung zu einem SMTP-Server aufbauen kann, zum Prüfen, ob er erreichbar ist, anschließend STARTTLS aktiviert um auf eine sichere Verbindung zu kommen und dann den Benutzer mit Passwort abzufragen, ob dieser angemeldet werden kann.
# Verbindung zu Web.de aufbauen
$c=Test-NetConnection smtp.web.de -Port 587
# Antwort vom SMTP-Server holen und ausgeben
[byte[]]$buffer= @(0) * $c.TcpClientSocket.Available
$c.TcpClientSocket.Receive($buffer)
[System.Text.Encoding]::ASCII.GetString($buffer)
# Begrüßung durchführen
$buffer=[System.Text.Encoding]::ASCII.GetBytes("EHLO $Env:Computername`r`n")
@newyear2006
newyear2006 / HyperVVMScreenCopy.PS1
Last active January 14, 2018 14:06
Zum Speichern und Anzeigen des aktuellen Bildschirm einer virtuellen Maschine
#
Add-Type -AssemblyName "System.Drawing"
Add-Type -AssemblyName "System.Windows.Forms"
function Get-VMScreenBMP {
param
(
$VMName,
$index=0
)
@newyear2006
newyear2006 / IsItPwned.PS1
Created February 28, 2018 12:56
Powershell-Abfrage, ob Passwort sicher ist
Function Get-PwnedPasswordCounter ($password) {
# Hashstring erzeugen
$sha1=[System.Security.Cryptography.SHA1]::Create()
$sha1Hash=$sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($password))
$sha1HashString=[System.BitConverter]::ToString($sha1Hash).Replace('-','')
$hashPrefix=$sha1HashString.Substring(0,5)
$hashSuffix=$sha1HashString.Substring(5)
# pwnedpasswords-API anrufen
@newyear2006
newyear2006 / GetThunderbirdPassword.CS
Created March 3, 2018 18:00
Firefox oder Thunderbird Passwörter auslesen, hier C# aber als Grundlage für späteres Powershellscript. Bei Thunderbird sind die Passwörter im logins.json file im Profile-Verzeichnis.
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
/// <summary>
/// A small class to recover Firefox Data
@newyear2006
newyear2006 / WindowsRuntimeRadio.PS1
Last active April 21, 2021 15:54
Bluetooth, WLAN und LTE-Modem über Powershell abfragen, ein- und ausschalten und weitere Spielereien mit Bluetooth
# Grundlage: Diese geniale Antwort auf Superuser: https://superuser.com/questions/1168551/turn-on-off-bluetooth-radio-adapter-from-cmd-powershell-in-windows-10/1293303#1293303
# Das Besondere daran, die Verwendung von Async und Await mit WindowsRuntime und alles in purem Powershell!
# hier nur die BluetoothVariante aber man kann durch Ändern der Kind-Abrage nach Wifi, MobileBroadband, FM und Other vorgehen. https://docs.microsoft.com/en-us/uwp/api/windows.devices.radios.radiokind
Function Bluetooth {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$BluetoothStatus
)
@newyear2006
newyear2006 / WindowsRuntimeAPIFeaturesDetection.PS1
Created March 5, 2018 20:39
UWP ApiFeatures per Powershell abfragen
# zunächst brauchen wir eine Windows Runtime Referenz
Add-Type -AssemblyName System.Runtime.WindowsRuntime
# dann die passende API-Laden, https://docs.microsoft.com/en-us/uwp/api/windows.foundation.metadata.apiinformation
[Windows.Foundation.Metadata.ApiInformation,Windows.Foundation.UniversalAPIContract,ContentType=WindowsRuntime]
# Featureabfrage
[Windows.Foundation.Metadata.ApiInformation]::IsTypePresent("Windows.Media.Playlists.Playlist")
# oder API-Contract mit Version
[Windows.Foundation.Metadata.ApiInformation]::IsApiContractPresent("Windows.Foundation.UniversalApiContract", 1,0)
# bisher bekannte API-Contracts: https://docs.microsoft.com/en-us/uwp/extension-sdks/windows-universal-sdk
# genauer: https://docs.microsoft.com/en-us/uwp/extension-sdks/