Skip to content

Instantly share code, notes, and snippets.

View techthoughts2's full-sized avatar
🕵️‍♂️
Investigating a better artifact workflow

Jake Morrison techthoughts2

🕵️‍♂️
Investigating a better artifact workflow
View GitHub Profile
@techthoughts2
techthoughts2 / StringManipulation.ps1
Last active September 5, 2021 16:28
String Manipulation
#replace
if($vDisk -contains " "){
$vDisk = $vDisk -replace(" ",",")
}
#remove last character
$string.Substring(0,$string.Length-1)
#extract a specific string set from a long string
@techthoughts2
techthoughts2 / UserChoices.ps1
Last active January 6, 2016 16:54
User Choices
#will we disable NICs in the team to determine if each NIC connection is good?
while("yes","no" -notcontains $Script:nicCheckSetting){
$Script:nicCheckSetting = Read-Host "Would you like to run the NIC Team connectivty check to check each NIC in the team? (yes/no)"
}
#for standalone Hyps - which drive will the VMs be stored on?
while("c:","d:","e:","f:","g:","h:","i:","j:","k:","l:","m:","n:","o:","p:","q:","r:","s:","t:","u:","v:","w:","x:","y:","z:" -notcontains $Script:vmVHDLocation){
$Script:vmVHDLocation = Read-Host "What drive letter will the VMs and VHDs be stored? (Ex. D: or S:)"
}
@techthoughts2
techthoughts2 / NewDirCheck.ps1
Last active September 26, 2022 12:02
Evaluates if a directory is present. if not found, the specified directory will be created.
if (-not(Test-Path -Path $TargetDir -ErrorAction Stop )) {
Write-Verbose -Message ('Output directory {0} not found. Creating...' -f $TargetDir)
$newItemSplat = @{
ItemType = 'Directory'
Path = $TargetDir
ErrorAction = 'Stop'
}
try {
New-Item @newItemSplat
Write-Verbose -Message 'Created.'
@techthoughts2
techthoughts2 / Test-Connectivity.ps1
Last active November 26, 2017 05:03
Evaluates if device is capable of establishing a connection to a specified server
#test connection example
$server = "Server01"
if (Test-Connection $server -Count 1 -ErrorAction SilentlyContinue) {
#connection successful
}
else {
#connection not successful
}
@techthoughts2
techthoughts2 / Get-WMIObject.ps1
Last active December 28, 2015 15:34
Get WMI data from local and remote devices
#---------------------------------------------------------------------
#get WMI data loaded up
#--------------------------------------------------------------------
try{
$w32ProcInfo = Get-WmiObject -Namespace "root\cimv2" -Class win32_processor -Impersonation 3 -ComputerName $node
$w32OSInfo = Get-WmiObject -Namespace "root\cimv2" -Class Win32_OperatingSystem -Impersonation 3 -ComputerName $node
}
catch{
Write-Host "An error was encountered getting WMI info from $node" -ForegroundColor Red
Write-Error $_
@techthoughts2
techthoughts2 / Test-Path.ps1
Last active November 14, 2017 04:09
Test if specified path actually exists
$path = "C:\Windows"
try {
if (Test-Path $path -ErrorAction Stop) {
Write-Output "Path exits"
}
else {
Write-Output "Path not found"
}
}
catch {
@techthoughts2
techthoughts2 / Get-FileSizes.ps1
Last active January 4, 2019 08:20
Contains a simple example for retrieving total directory size for all files within a directory. Also contains a more in depth example for retrieving file size as well as other related file information from a directory path.
#how to get files and ignore directories
$sizes = Get-ChildItem -Path C:\dell\suu -Recurse -ErrorAction Stop | Where-Object { ! $_.PSIsContainer } | Select-Object -ExpandProperty Length
#simple example
#---------------------------------------------------------
$path = "C:\Test"
#---------------------------------------------------------
$size = (Get-ChildItem -Path $path -Force -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
"Folder Size: $size Bytes"
'Folder Size: {0:n2} MB' -f ($size/1MB)
@techthoughts2
techthoughts2 / Expand-ZipFile.ps1
Last active October 18, 2017 03:49
The PowerShell Expand-ZipFile will extract zip files to the specified location.
<#
.Synopsis
Expand-ZipFile will extract zip files to the specified location
.DESCRIPTION
Expand-ZipFile will extract a zip file and put the extracted contents in the specified location.
This is the second code block that I have not hand-written
#>
function Expand-ZipFile {
#.Synopsis
# Expand a zip file, ensuring it's contents go to a single folder ...
@techthoughts2
techthoughts2 / Get-GeneralInfo.ps1
Created December 28, 2015 15:49
Get general device information loaded up
<#
.Synopsis
Get-GeneralInfo gathers general info about the device to provide in the output
.DESCRIPTION
Get-GeneralInfo gathers general info about the device including hostname, model to display in the final output
#>
function Get-GeneralInfo {
#--------------------------------------------------------------------------------------
#Getting the host name with error control
try{
@techthoughts2
techthoughts2 / Test-WinRM
Last active November 14, 2017 04:03
Verifies if remote WinRM Powershell commands can be run against another device by verifying WinRM connectivity to the specified computer name over both HTTP and HTTPS. Returns a customer PSObject containing boolean value for both HTTP and HTTPS results.
<#
.Synopsis
Tests WinRm connectivity to specified computername via HTTP and HTTPS
.DESCRIPTION
Evaluates both HTTP and HTTPS connectivity over WinRM to specified computername. Returns PSObject with Boolean value for HTTP and HTTPS based on results.
.PARAMETER ComputerName
Hostname of device you wish to test WinRM connection to
.EXAMPLE
Test-WinRM -ComputerName HYP1