Skip to content

Instantly share code, notes, and snippets.

@tikg
Last active February 16, 2023 00:49
Show Gist options
  • Select an option

  • Save tikg/2ee9448a3d3ef6e428ef43224ea9cd8a to your computer and use it in GitHub Desktop.

Select an option

Save tikg/2ee9448a3d3ef6e428ef43224ea9cd8a to your computer and use it in GitHub Desktop.

Microsoft Powertoys

winget install Microsoft.PowerToys --source winget

Powershell Latest Release

Here

Allowing Scripts to be run

To solve: Solution for “cannot be loaded because running scripts is disabled on this system“:

Get-ExecutionPolicy  
Set-ExecutionPolicy RemoteSigned

Windows Health Check for Drives

Dism /Online /Cleanup-Image /CheckHealth  
Dism /Online /Cleanup-Image /ScanHealth  
Dism /Online /Cleanup-Image /RestoreHealth  
sfc /scannow

robocopy general syntax (l is for list, remove when sure)

robocopy /move /e /s /w:99 /r:10 [from] [to] /l

triple quote for find to avoid "FIND: Parameter format not correct" error

PS C:\pomerium> netstat -ano -p tcp | find """200"""
  TCP    10.81.135.240:54184    13.107.21.200:443      ESTABLISHED     9472
  TCP    10.81.135.240:62618    204.79.197.200:443     ESTABLISHED     11812
  TCP    127.0.0.1:20080        0.0.0.0:0              LISTENING       18668

Naming convention script

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$ErrorActionPreference = 'SilentlyContinue'
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator'))
{
Start-Process powershell.exe "-NoProfile -windowstyle hidden -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
Exit
}
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = New-Object System.Drawing.Point(300,150)
$Form.text = "Script rename By Julian Naylor"
$Form.StartPosition = "CenterScreen"
$Form.TopMost = $false
$Form.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#e9e9e9")
$Form.AutoScaleDimensions = '192, 192'
$Form.AutoScaleMode = "Dpi"
$Form.AutoSize = $True
$Form.AutoScroll = $True
$Form.ClientSize = '300,300'
$Form.FormBorderStyle = 'FixedSingle'
$Panel1 = 150
$Panel1.width = 150
$Panel1.location = New-Object System.Drawing.Point(6,54)
$runsc = New-Object System.Windows.Forms.Button
$runsc.Text = "Run script"
$runsc.Width = 212
$runsc.height = 30
$runsc.Location = New-Object System.Drawing.Size(0,5)
$runsc.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12)
$Form.Controls.Add($runsc)
$ResultText = New-Object system.Windows.Forms.TextBox
$ResultText.multiline = $true
$ResultText.width = 382
$ResultText.height = 130
$ResultText.location = New-Object System.Drawing.Point(0,155)
$ResultText.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12)
$Form.controls.AddRange(@($Panel1,$ResultText))
$Panel1.controls.AddRange(@($runsc))
Function Add-OutputBoxLine {
Param ($Message)
$ResultText.AppendText("`r`n$Message")
$ResultText.Refresh()
$ResultText.ScrollToCaret()
}
############Sets computer name#################
$runsc.Add_Click({
Function get-devicetype
{
Param(
[string]$unit = “localhost”
)
$result = $false
if(Get-WmiObject -Class win32_systemenclosure -ComputerName $unit |
Where-Object { $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 `
-or $_.chassistypes -eq 14})
{ $result = $true }
if(Get-WmiObject -Class win32_battery -ComputerName $unit)
{ $result = $true }
$result
}
$type = If(get-devicetype) { “L” }
else { “D”}
$SerialNumber = (Get-WmiObject -class win32_bios).SerialNumber
$name = "test-$SerialNumber-$type" ###############<---this is the computer name entry change test to the name of company##
Rename-Computer -NewName $name -Force
Add-OutputBoxLine -Message "computer renamed to test-$SerialNumber-$type"#cosmetic for result text when script finishes change test to company name##
}
)
[void]$Form.ShowDialog()

install firefox silently

(New-Object System.Net.WebClient).DownloadFile("https://download.mozilla.org/?product=firefox-latest-ssl...", "$env:temp\FirefoxSetup.exe")
Start-Process -FilePath "$env:temp\FirefoxSetup.exe" -ArgumentList '/S' -Wait

or

$url = "https://download.mozilla.org/?product=firefox-latest..."
$file = "FirefoxSetup.exe"
Invoke-WebRequest -Uri $url -OutFile $file
Start-Process -FilePath $file -ArgumentList '/S'
@tikg
Copy link
Author

tikg commented Feb 10, 2023

resetting your password when you're logged in but forgot password

Run powershell as admin

net user "username" passwordyoulike

image

@tikg
Copy link
Author

tikg commented Feb 14, 2023

no idle powershell script

param($minutes = 60)
$myshell = New-Object -com "Wscript.Shell"
for ($i = 0; $i -lt $minutes; $i++) {
Start-Sleep -Seconds 60
$myshell.sendkeys(".")
}

Replace . with {SHIFT} or something if needed

@tikg
Copy link
Author

tikg commented Feb 16, 2023

mouse click automation

getting mouse position from screen

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$signature=@'...
$SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru
$X = [System.Windows.Forms.Cursor]::Position.X
$Y = [System.Windows.Forms.Cursor]::Position.Y
Write-Output "X: $X | Y: $Y"

Sample:

X: 1253 | Y: 456

click after sleep / time

$x = 86
$y = 172
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
sleep -Seconds 01
$SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
$SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);

More info on URL

@tikg
Copy link
Author

tikg commented Feb 16, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment