Month: December 2019

PowerShell: Create and Delete VSS Snapshots

Update 7/30/20: use this newer version # There are 2 functions in this snippet# 1.…

PowerShell: Get ‘Size on Disk’ of Files in Windows

There are many methods of attempting to obtain "size on disk" values of files in…

PowerShell: Start-Job, Get-Job, Receive-Job Examples

Demo 1: Obtain Public IP of a Windows Machine # Commands to run locally$command1={(Invoke-WebRequest -URI…

PowerShell: Nesting Functions Inside Functions

Demo 1: calling a function from within another function function A{ Param($functionToCall) Write-Host "Calling function:…

PowerShell: Working With Arrays

Problem: elements of a System.Array couldn't be counted # Example output when an object is…

PowerShell: Obtain Computer Account Parent Container from Invoke-Command

# ObtainComputerAccountParentContainer.ps1# This is a demonstration of how to pass function into an invoke-command as…

PowerShell: Snippet to Detect and Disconnect Active PS Sessions

# Manual DetectionPS C:\Windows\system32> get-pssession Id Name ComputerName ComputerType State ConfigurationName Availability -- ---- ------------…

PowerShell: Compare Time Stamps of Items in Mirroring Directories

# compareTimeStamps.ps1# Set variables$source="T:\DIRECTORY1"$destination="\\FILESHERVER\DIRECTORY1"$sampleSize=100$logFile="\\FILESHERVER\SHERVER1\sampleTimeStampLog.txt"function sampleTimeStamp{ param( [string]$sourceDirectory=$source, [string]$destinationDirectory=$destination, [int]$sampleCount=$sampleSize, [string]$timeStampLog=$logFile ) $timeStampTimer=[System.Diagnostics.Stopwatch]::StartNew() # Enable Remote…

Resolve Windows 2003 Logon Screen Blackout Problems

The problem:Administrators are unable to logon to a Windows 2003 Server. This is what they…

PowerShell: Setting Windows Firewall Rules

# Set variables for HTTP$protocolName="HTTP"$protocol="TCP"$portNumbers='80','443'$direction="Inbound"$scopes='Domain', 'Private'# Add Firewall RuleNew-NetFirewallRule -DisplayName "$protocolName-$direction" -Profile @($scopes) -Direction $direction…

PowerShell: Check VLAN of Windows Machine

Le Kommand: Get-NetAdapter|select Name,VlanID Sample Outputs PS C:\Windows\system32> Get-NetAdapter|select Name,VlanIDName VlanID---- ------Ethernet 1 0 PS…

PowerShell: Set ACL

# setAcl-v0.01.ps1# # What this script does:# 1. Set permissions on a set of "destination…

PowerShell: Moving Virtual Machines & Expanding Disk Volumes in Hyper-V & Microsoft Failover Clusters

Sample VM Migation Plan (time window = 3 hours): Pre-emptively resolve disks merging errors prior…

PowerShell: Remove Nic Teaming

# Check NIC TeamingPS C:\Windows\system32> get-NetLbfoTeamName : ISCSIMembers : {iSCSI-B, iSCSI-A}TeamNics : ISCSITeamingMode : SwitchIndependentLoadBalancingAlgorithm…

Linux: MySql Docker Container – Export database

# Set VariablessqlContainer="mysql-server"userName=bruceleepassword=chucknorrisdatabaseName=kimconnect# Run mysql inside containerdocker exec -it  $sqlContainer mysql -u$userName --password='$password'show databases;# Execute mysqldumpdocker exec $sqlContainer /usr/bin/mysqldump…

PowerShell: Copying Only Files From a Folder

Function (snippet): function copyOnlyFiles{ param( [Parameter(Mandatory=$true)][string]$sourceFolder, [Parameter(Mandatory=$true)][string]$destinationFolder ) $totalSizeBytes=0; # Get-ChildItem "C:\Temp"|?{!$_.PSIsContainer}|%{robocopy "C:\Temp" "C:\TempCopy" $_}…

PowerShell: Install Visual Studio 2019 Community Version

# 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 Size On Disk and Discover Largest Files in a Given Directory

# getSizeOnDisk-v0.01.ps1# Set variables$parentDirectory="C:\"$depth=4$topX=10$excludeDirectories="C:\Windows","C:\Program Files","C:\Program Files (x86)"$clusterSizeOfNetworkShare=8192# sanitateif($depth -le 1){$depth=1}################################## Excuting Program as an Administrator…

Setting Up Python on a Windows Machine

# Install Visual C++ 14choco install vcredist2017 -y# Install Python 3.8choco install python --version=3.8 -y#…

Dev Environment Technitium DNS Server

Windows: $technitiumPortableDownload="https://download.technitium.com/dns/DnsServerPortable.zip"$tempDir="C:\Temp"; $extractionDir="C:\Technitium" $destinationFile = "$tempDir\DnsServerPortable.zip"; try{[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12}catch{} New-Item -ItemType Directory -Force -Path $tempDir…