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 / GoogleTimeOutFix.gs
Created February 14, 2017 16:31
Shows an example of getting out of code to not show the error message "time exceeded"
function isTimeUp_(start) {
var now = new Date();
return now.getTime() - start.getTime() > 300000; // 5 minutes
}
function myFunction() {
var threads = GmailApp.getInboxThreads(0, 50);
var start = new Date();
@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 {
@pcast01
pcast01 / jithinjacob_getdata.gs
Last active January 21, 2018 09:49
FiverrUsername_ProjectName.gs - includes MomentAzrael ProjectID: M_T9Pc2Plt8hZ0Zh1LUfaAOvctAQHFBqM
function onOpen(){
SpreadsheetApp.getUi().createMenu("OI Tracker")
.addItem("Zero out cells", "zeroOutOitSheet")
.addItem("List OI and LP", "listOiLp")
.addToUi();
}
function refreshImport() {
var queryString = Math.random();
//Logger.log("random: " + queryString);
@pcast01
pcast01 / CustomFunction.gs
Last active January 21, 2018 09:50
Custom Google Sheets Function
/** Brings two columns of strings together.
*
* @param {string} First string.
* @param {string} Second string.
* @return both strings together.
* @customfunction
**/
function COMBINESTRINGS(first, second) {
return first + ' ' + second;
}
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){
@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
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'