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 / Sort-Movie-Files.ps1
Last active October 18, 2017 03:49
It is common when sorting digital movie collections to sort in a directory/movie-file type format where the directory and movie-file share the same name. Example: Godfather/Godfather.mkv This sorting script is capable of scanning an entire directory, and then creating directory folders based off of the movie file name. It will then move the file…
#gets all files from specified path. scans each file and gets the BaseName of the file.
#script will create a directory for each BaseName and move the file to that new BaseName directory.
#this can be handy for things like sorting a digital movie collection.
#---------------------------------------------------------
$path = "V:\Movies\Sci-FI Top 50 movies\"
#---------------------------------------------------------
$files = Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue | `
Where-Object {$_.BaseName -notlike "Thumbs" -and $_.PSIsContainer -eq $false}
#$files #uncomment if you would like to display a list of the files to be moved
foreach ($file in $files) {
@techthoughts2
techthoughts2 / Date_Manip.ps1
Last active August 8, 2016 17:09
Date manipulation
$certInfo = ls Cert:\LocalMachine\My | where { $_.Subject -eq $subject }
$expireDate = $certInfo.NotAfter
[int]$daysRemaining = New-TimeSpan -End $expireDate | Select-Object -ExpandProperty Days
$date = Get-Date
$1weekOut = $date.AddDays(7)
@techthoughts2
techthoughts2 / progressBar.ps1
Last active August 24, 2018 15:26
Progress Bar
Write-Progress -Activity "Test" -PercentComplete 25
Start-Sleep(5)
Write-Progress -Activity "Test" -PercentComplete 50
Start-Sleep(5)
Write-Progress -Activity "Test" -PercentComplete 75
Start-Sleep(5)
Write-Progress -Activity "Test" -PercentComplete 100
#secind example of progress bar
$seconds = 60
@techthoughts2
techthoughts2 / basics.ps1
Last active December 1, 2021 04:18
Basic Info
#get the domain
$domain = $env:USERDNSDOMAIN
#Get Operating System Info
$sOS = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty Caption
try {
$sOS = Get-WmiObject -class Win32_OperatingSystem
$Script:OS = $sOS.Caption
}
@techthoughts2
techthoughts2 / suffixes.ps1
Last active January 6, 2017 21:59
DNS Suffixes
#set suffixes
$suffixes = "suffix1.int,suffix2.int,suffix3.int"
$command = @"
cmd.exe /C "wmic nicconfig call SetDNSSuffixSearchOrder ($domain,$suffixes)"
"@
Invoke-Expression -Command:$command -ErrorAction SilentlyContinue
#------------------------------------------------------------------------------
#reverse suffixes change
#Append Primary and connection specific DNS suffixes
#Append parent suffixes of the primary DNS suffix
@techthoughts2
techthoughts2 / Verify_Windows_CompName
Last active February 5, 2021 18:06
This retrieves the computer name and then regex validates that name against common windows machine name requirements. If the computer name matches Windows name requirements it will return true, otherwise it will return false.
<#
.Synopsis
Verifies if computername matches Windows machine naming requirements
.DESCRIPTION
This function accepts a computername string and regex verifies if that name meets Windows machine naming requirements
.PARAMETER ComputerName
String of computername to be tested
.EXAMPLE
Test-ComputerName -ComputerName PC-Num-43123
This will verify if the computer name meets windows requirements
@techthoughts2
techthoughts2 / FileRemove.ps1
Last active October 18, 2017 03:48
Test for a file and remove the file if found.
#tests for file and if found removes the file.
#---------------------------------------------------------
$path = 'C:\path\Test.txt'
#---------------------------------------------------------
if (Test-Path $path) {
Write-OutPut "$path detected, removing file before starting..."
try {
Remove-Item -Path $path -Force -Confirm:$false -ErrorAction Stop
}
catch {
@techthoughts2
techthoughts2 / secureString.ps1
Last active November 27, 2016 03:37
Convert a plain text string to a secure string
$password = Read-Host "Enter your password"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
@techthoughts2
techthoughts2 / Shares.ps1
Created January 23, 2017 21:40
Create a folder share
$Shares=[WMICLASS]”WIN32_Share”
$Shares.Create("C:\folder\provisioning","Everyone",0)
@techthoughts2
techthoughts2 / cmd_commands.ps1
Last active August 24, 2018 14:31
Running commands in CMD from powershell
$command = 'C:\somepath\someexe.exe somearg'
iex $command
#full working example
$command = 'cmd.exe /c "C:\Program Files (x86)\Bginfo\BgInfo.exe" "C:\Program Files (x86)\Bginfo\config_2016.bgi\" /silent /accepteula /timer:0'
iex "& $command"
#issue the command
cmd.exe /c dir /w