Skip to content

Instantly share code, notes, and snippets.

@PowerShell -NoP -C "&([ScriptBlock]::Create((Get-Content '%~f0'|?{$_.ReadCount -gt 1}|Out-String)))" & exit
# by earthdiver1
###################################################################################################################################
$src_file = "C:\:somedir\important_file.doc"
$dst_dir = "D:\backup"
$num_copy = 20
$interval_1 = 180
$interval_2 = 15
###################################################################################################################################
$ErrorActionPreference = "Stop"
@earthdiver
earthdiver / convert-ps1-to-bat
Last active April 29, 2024 14:27
One-line preambles to convert a PowerShell script into a batch file.
@Powershell -NoP -C "$input|&([ScriptBlock]::Create((gc '%~f0'|?{$_.ReadCount -gt 1}|Out-String)))" %* & pause & exit/b
@Powershell -NoP -C "$PSCommandPath='%~f0';$PSScriptRoot='%~dp0'.TrimEnd('\');$input|&([ScriptBlock]::Create((gc '%~f0'|?{$_.ReadCount -gt 1}|Out-String)))" %* & pause & exit/b
@Powershell -NoP -C "$input|.([ScriptBlock]::Create('$MyInvocation.MyCommand|Add-Member -M NoteProperty -Na Path -V ''%~f0'';$PSCommandPath=''%~f0'';$PSScriptRoot=''%~dp0''.TrimEnd(''\'');'+(gc '%~f0'|?{$_.ReadCount -gt 1}|Out-String)))" %* & pause & exit/b
@setlocal EnableDelayedExpansion&set a=%*&(if defined a set a=!a:"=\"!)&Powershell -NoP -C "$PSCommandPath='%~f0';$PSScriptRoot='%~dp0'.TrimEnd('\');$input|.([ScriptBlock]::Create(((gc '%~f0'|?{$_.ReadCount -gt 1}|Out-String)-replace'(?is)(^^(?:(?(o)(?:(?^!<#|@[''\""])[^^\s#''\""()])+|(?^!))|\s+|#[^^\n]*\n|<#(?:[^^#]|#(?^!>))*#>|''(?:[^^''`]|`.)*''|\""(?:[^^\""`]|`.)*\""|@''(?:(?^!\n''@).)*\n''@|@\""(?:(?^!\n\""@).)*\n\""@|\[(?:Alias|CmdletBinding)[^^\]]*\]|\[Ou
@earthdiver
earthdiver / taskbar.ps1
Last active May 11, 2024 10:15
A code snippet to put a resident PowerShell script into the taskbar notification area
#@Powershell -NoP -W Hidden -C "$PSCP='%~f0';$PSSR='%~dp0'.TrimEnd('\');&([ScriptBlock]::Create((gc '%~f0'|?{$_.ReadCount -gt 1}|Out-String)))" %* & exit/b
# by earthdiver1 V1.05
if ($PSCommandPath) {
$PSCP = $PSCommandPath
$PSSR = $PSScriptRoot
$code = '[DllImport("user32.dll")]public static extern bool ShowWindowAsync(IntPtr hWnd,int nCmdShow);'
$type = Add-Type -MemberDefinition $code -Name Win32ShowWindowAsync -PassThru
[void]$type::ShowWindowAsync((Get-Process -PID $PID).MainWindowHandle,0)
}
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
@earthdiver
earthdiver / arping.bat
Created April 29, 2024 07:00
An arping tool for Windows. ( Use the function inside on Powershell console. )
@Powershell -NoP -C "&([ScriptBlock]::Create((gc '%~f0'|?{$_.ReadCount -gt 1}|Out-String)))" %* & exit/b
# by earthdiver1
[CmdletBinding(PositionalBinding=$False)]
Param(
[parameter(Position=0)][String]$Target, # IP address of the target host
[String]$Source, # if you have multiple interfaces (optional, default value: 0 (all interfaces))
[Alias("n")][Int]$Count=4, # the number of ARP requests to send (optional, default value: 4)
[Int]$Interval=1 # the interval between ARP requests, in seconds (optional, default value: 1)
)
using namespace System.Numerics
<#
.SYNOPSIS
A tool that enables the use of the PowerShell console as a scientific calculator.
.DESCRIPTION
Accepts standard mathematical expressions as input and outputs the results on the console by
internally converting the expressions into forms that PowerShell can parse.
If no expression is specified as an argument, a read-eval-print-loop (REPL) session will start.
Intended for interactive use.
<#
.SYNOPSIS
A grep-like tool with a color highlighting feature.
.DESCRIPTION
This function searches for text patterns in input strings.
If input is an object, it is converted to a string prior to processing.
Matched characters are highlighted.
'(some command) | Select-MatchedString -Pattern <regex>'