This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lowercase letters/numbers only | |
| -join ((48..57) + (97..122) | Get-Random -Count 32 | % {[char]$_}) | |
| # all characters | |
| -join ((33..126) | Get-Random -Count 32 | % {[char]$_}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = 'Stop' | |
| try | |
| { | |
| npm install bogus-package 2>&1 | |
| } | |
| catch | |
| { | |
| Write-Host "Error: $_" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dd if=/dev/urandom bs=1 count=64 2>/dev/null | base64 --wrap 0 && echo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NAME=test-cert | |
| # generate key | |
| openssl genrsa -out $NAME.key 2048 | |
| # generate certificate request | |
| openssl req -new -sha256 -key $NAME.key -out $NAME.csr | |
| # self-sign certificate (if not sending to CA) | |
| openssl x509 -req -days 3650 -in $NAME.csr -signkey $NAME.key -out $NAME.crt | |
| # convert to pfx | |
| openssl pkcs12 -export -out $NAME.pfx -inkey $NAME.key -in $NAME.crt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # configure | |
| $cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName $env:COMPUTERNAME | |
| Enable-PSRemoting -SkipNetworkProfileCheck -Force | |
| New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint –Force | |
| New-NetFirewallRule -DisplayName "Windows Remote Management (HTTPS-In)" -Name "Windows Remote Management (HTTPS-In)" -Profile Any -LocalPort 5986 -Protocol TCP | |
| # connect | |
| Enter-PSSession -ComputerName {X.X.X.X} -Credential (Get-Credential) -SessionOption (New-PsSessionOption -SkipCACheck -SkipCNCheck) -UseSSL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Write-Output "starting ..." | |
| $dataSource = 'tcp:{server},1433' | |
| $user = '{user}' | |
| $pwd = '{pass}' | |
| $database = '{db}' | |
| $connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;" | |
| try | |
| { | |
| $query = "SELECT 1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Trace-Port([string]$IPAddress="127.0.0.1", [int]$Port=80, [switch]$Echo=$false){ | |
| $listener = new-object System.Net.Sockets.TcpListener([System.Net.IPAddress]::Parse($IPAddress), $port) | |
| $listener.start() | |
| [byte[]]$bytes = 0..255|%{0} | |
| write-host "Waiting for a connection on port $port..." | |
| $client = $listener.AcceptTcpClient() | |
| write-host "Connected from $($client.Client.RemoteEndPoint)" | |
| $stream = $client.GetStream() | |
| while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Add-Content $Profile @" | |
| Set-PSReadlineOption -HistorySavePath "$env:USERPROFILE\OneDrive\AppData\PSReadLine\ConsoleHost_history.txt" | |
| "@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for($i=(get-date);$i.AddMinutes(1) -gt (get-date);){} |