Month: January 2020

PowerShell: Windows File Migration Tool Using VSS & FastCopy

Update: FastCopy doesn't properly update NTFS permissions of parent directories nor files if those items…

PowerShell: Hobocopy Backup Software

# hobocopy-backup.ps1# Note: this is a quick snippet to demonstrate the use of this utility.#…

PowerShell: Get CRC Signature of a File

2/10/20 Update: xxHash will beat both of these in term of speed. Hence, this blog…

PowerShell: Get MD5 Hashing Signature of a File

# Get-MD5-Hash.ps1# Get-FileHash (PowerShell 4.0+) replacement for Windows 2008. Forward-compatible.function getMd5{ param( $file, $md5 =…

PowerShell: Find Process IDs of a Locked File and Kill It

There's a newer iteration of this function here. $targetFile='C:\Users\kimconnect\Desktop\testfile.csv' function killPidLockedFile($filename){ if (!(Get-Command handle.exe -ErrorAction…

PowerShell: Purge User Outlook Profile

# Purge-User-Outlook-Profile.ps1# Set folder path$folderToDelete="$env:localappdata\Microsoft\Outlook";function purgeFolder($path){ mkdir c:\temp -force -ea SilentlyContinue | out-null cd c:\temp…

PowerShell: How To Make A System App Do Nothing

# How-To-Make-Existing-System-App-Do-Nothing.ps1# Provide variables$hive="REGISTRY::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WORDPAD.EXE"$key="(default)"$value="C:\Windows\dummy.exe"$defaultValue="C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"# Dummy-File-Creator.ps1$dummyFile="C:\Windows\dummy.exe"$output = new-object byte[] 1; (new-object Random).NextBytes($output);[IO.File]::WriteAllBytes($dummyFile, $output);if…

PowerShell: Perform Final Sync Between 2 Directories

Current Version # Final-Sync.ps1# This function performs CRC checks on each file at the source.#…

Active Directory: How to Copy Account

Run: DSA.MSC > navigate to the container of the user to be copied (e.g. Test…

Active Directory: How to Disable Account

RDP into a domain controller > Right-click the Windows icon on the bottom left corner…

PowerShell: Change Process Priority Level

Most programs would launch with normal priories and trigger child processes with varying priority levels,…

PowerShell: Check TCP Connections of Server by Port Numbers

# Check-TCP-Connections.ps1# This function will output progress onto the console as well as returning a…

PowerShell: Stop Any Service on Windows!

Problem: some system protected services cannot be stopped. PS C:\Users\KingKong> stop-service msmpsvcStop-Service : Service 'Microsoft…

PowerShell: Implementation of Anonymous Self Executing Function

JavaScript has this. It's a little known secret that PowerShell can do this as well.…

PowerShell: Copy SMB Share Permissions from Legacy Sources

Scenario:Windows 2008 File Servers migration lacks a built-in function to clone Share Permissions - Get-SmbShareAccess…

PowerShell: Install DotNet 3.5 – the Easy Way

$package="dotnet3.5"# Install Chocolateyif (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) {Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))}#…

PowerShell: Get Hyper-V Host Name from Inside Guest VM

$guestVMName="SOMENAME"function getHyperVHostname{ param([string]$guestVMName=$env:computername) $hive = [Microsoft.Win32.RegistryHive]::LocalMachine; $keyPath = 'SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters'; $value = 'HostName'; $reg =…

PowerShell: Search for Failed Logins on Primary Domain Controller

# Quick Script to search for failed logins$daysLimit=7$userName="Bruce"$todaysDate= Get-date$pdc = (Get-ADDomain).PDCEmulator #$allDCs = ((Get-ADForest).Domains |…

PowerShell: Check if a HostName is Resolvable on All Internal DNS Servers

# Check if servername is resolvable at all DCs$serverName="MIGRATED-SHERVER" function checkDns{ param( $serverName, $dnsServers=(Get-ADDomainController -Filter…

PowerShell: Delete Hidden System Volume Information Directory

# Incident:The System Volume Information has been copied over to an SMB share, where such…