Skip to content

Instantly share code, notes, and snippets.

View pcast01's full-sized avatar

Paul pcast01

View GitHub Profile
Function Format-FileSize() {
Param ([int]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
ElseIf ($size -eq 0) {"0 MB"}
Else {""}
}
@pcast01
pcast01 / CustomFilesSearch.ps1
Last active January 9, 2017 19:43
Search for files using multiple paths and multiple pattern searches.
#Requires -Version 3.0
Function Format-FileSize {
Param ([int64]$Size)
# Based on File.Length in bytes return appropriate size
Switch($Size)
{
{ $_ -gt 1TB }
{"{0:0.00} TB" -f ($Size / 1TB); break}
@pcast01
pcast01 / FormSubmitFallback.gs
Created February 14, 2017 15:27 — forked from erickoledadevrel/FormSubmitFallback.gs
Demonstrate how to create a form submit processing script that can handle missing or duplicate trigger firings.
// Change this values based on your spreadsheet.
var SHEET_NAME = 'Form Responses 1';
var STATUS_COLUMN_NUMBER = 4;
var PROCESSED_STATUS = 'Processed';
var LAST_ROW_KEY = 'lastRow';
var LOCK_TIMEOUT_MS = 60000; // 1 minute
var MAX_RUNTIME_MS = 240000; // 4 minutes
/**
@pcast01
pcast01 / GA-sort-two-columns.js
Created February 16, 2017 22:18 — forked from sco-tt/GA-sort-two-columns.js
This Google Apps Script sorts two columns. Variables can be modified to define what two columns should be sorted, and whether they should be ascending or descending.
/** Build a menu item
From https://developers.google.com/apps-script/guides/menus#menus_for_add-ons_in_google_docs_or_sheets
**/
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createMenu('Sort');
if (e && e.authMode == ScriptApp.AuthMode.NONE) {
// Add a normal menu item (works in all authorization modes).
menu.addItem('Sort Sheet', 'sort');
} else {
Import-Module C:\Users\USERPROFILE\Downloads\UIAutomation.0.8.7B3.NET40\UIAutomation.dll
[UIAutomation.Preferences]::Highlight = $false
[UIAutomation.Preferences]::Log = $false
[UIAutomation.Preferences]::AutoLog = $false
[UIAutomation.Preferences]::OnErrorScreenShot = $false
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
function Connect-VPN() {
$vpnUI = Get-Process | Where-Object {$_.Name -like "vpnui"}
if($vpnUI){
New-ADUser -EmployeeID $employeeId -SamAccountName $newLogin -UserPrincipalName $userPrincipalName
-GivenName $firstName -Surname $lastName -DisplayName $displayName -path $path
-Company $company -Fax $fax -OfficePhone $phone
-Title $title -EmailAddress $email -Enabled 1 -name $name
-AccountPassword (ConvertTo-SecureString -AsPlainText $password -Force) -ChangePasswordAtLogon 1
New-ADUser -EmployeeID '10551' -SamAccountName 'taylortobaben' -UserPrincipalName 'taylortobaben@samim.com'
-GivenName 'Taylor' -Surname 'Tobaben' -DisplayName 'Tobaben, Taylor' -path 'Immediadent'
-Company 'Immediadent' -Fax '' -OfficePhone '9132232051'
-Title 'Test Title'
@pcast01
pcast01 / 0_reuse_code.js
Created September 2, 2017 16:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@pcast01
pcast01 / Set_usergroups.ps1
Last active September 2, 2017 18:38
Set User Group in AD
function Set-UserGroups($loginName, $employeeType, $dept, $state, $regionId, $pc)
{
# Load the groups from the external group_arrays file.
# Use this file to manage all groups and changes to groups
# Blocking out for now and loading the groups as part of this main script.
#. .\group_arrays.ps1
# THESE ARE SAMSON EMPLOYEE groups
$SAMSON_Array = @("!All_Samson_Employees", "!SamsonEmployees", "Domain Users", "Infosource", "Samson_Internet")
@pcast01
pcast01 / TestAD.ps1
Last active September 2, 2017 18:38
New AD User
Start-Transcript -Path "C:\bin\ps\Account_Automation\TestAD.txt"
# Import the Active Directory cmdlets
Import-Module ActiveDirectory
New-ADUser -EmployeeID '10551' -SamAccountName 'taylortobaben' -UserPrincipalName 'taylortobaben@samim.com'
-GivenName 'Taylor' -Surname 'Tobaben' -DisplayName 'Tobaben, Taylor' -path 'Immediadent'
-Company 'Immediadent' -Fax '' -OfficePhone '9132232051'
-Title 'Test Title' -EmailAddress 'taylortobaben@immediadent.com' -Enabled 1 -name 'Taylor Tobaben'
-AccountPassword (ConvertTo-SecureString -AsPlainText '1234!$SamsonDent' -Force) -ChangePasswordAtLogon 1
@pcast01
pcast01 / Encrypt string.ps1
Last active September 2, 2017 18:39
Powershell Encrypt String
# Get Password into txt file
Read-Host "Enter Password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\Temp\Password.txt"
# Read it from text file.
$pass = Get-Content "C:\Temp\Password.txt" | ConvertTo-SecureString
$passwordplain = ConvertFrom-SecureToPlain $pass
$passwordplain