Skip to content

Instantly share code, notes, and snippets.

View royashbrook's full-sized avatar

Roy Ashbrook royashbrook

View GitHub Profile
@royashbrook
royashbrook / genDimDate.cs
Created June 30, 2014 20:07
Generate Dimension Table in C#
//uses LINQPad
void Main()
{
List<dimDate> dimDates = genDimDate(
DateTime.Parse("1/1/2012")
, DateTime.Parse("12/31/2017")
);
dimDates.Dump();
}
@royashbrook
royashbrook / IterateOverWordFields.cs
Created June 30, 2014 20:53
iterate over word fields and formfields in LINQPad
void Main()
{
string sPath = @"c:\temp\somedoc.docx";
ShowFields(sPath);
}
//using Microsoft.Office.Interop.Word
void ShowFields(string sPath)
{
//references for the com objects
Application oApp = null;
@royashbrook
royashbrook / Make_RasPi_SDC.sh
Last active May 17, 2017 01:41
image raspi
# first, download image to somewhere
# make a note of the location
# i am going to use:
# ~/Downloads/2017-04-10-raspbian-jessie-lite.img
read -n 1 -s -p "Download the image and press any key to continue..."
# i sudo bash first
sudo bash
# let's get the current disks
#plaintext password
$pt= "P@ssword1"
$pt
#convert to secure string object
$oss= $pt | ConvertTo-SecureString -AsPlainText -Force
$oss
#secure string object as a string, this is what you store in a file
$sss= $oss| ConvertFrom-SecureString
#get local accounts from a list of servers
# get the list, make sure the servers pass a ping check, pull back the account list
# ignore the errors, we only care about the stuff we *can* reach
# uses servers.csv file with a Name column as input
# outputs to accounts.csv
$servers = $null # server list, pulled name and sorted from csv
$pj = $null # ping job
$pr = $null # ping results
$upservers = $null #servers who were pinged successfully
#Import CSV, dynamically generate column names
Import-Csv -Header (00..( (gc file.csv)[0].split(",").Count-1 )|%{"c{0}" -f $_}) -Path file.csv
#ternary
@('false','true')[$true]
## Send me an email
Send-MailMessage `
-From "name <emailaddress@domain.com>" `
-To @("me <myemailaddress@domain.com>") `
-Attachments $fi.FullName `
-SmtpServer "10.10.10.10" `
-Port 25 `
-Subject "Subject" `
-Body "PFA File: $($fi.Name)"
##Inventory a list of machines:
"server1","server2" | % {
$c = $_ #var to hold computer name
$o = @() #hashtable to hold results
$o += Get-WmiObject -ComputerName $c -Class Win32_OperatingSystem
$o += Get-WmiObject -ComputerName $c -Class Win32_BIOS
$o += Get-WmiObject -ComputerName $c -Class Win32_ComputerSystem
$o += Get-WmiObject -ComputerName $c -Class Win32_Processor
$o += Get-WmiObject -ComputerName $c -Class Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
$o
# Find users by properties:
Get-ADUser -f {name -like '*ashbrook*'}
Get-ADUser -f {givenname -like '*roy*'}
Get-ADUser -f {surname -like '*ashbrook*'}
Get-ADUser -f {mail -eq 'myemail@domain.com'}
Get-ADUser -Filter {surname -eq "ashbrook"} | measure
#Reset User Password:
function Set-Pass {
Param ($Identity, $PlainTextPassword)
$a = $Identity
$b = $PlainTextPassword
$c = ConvertTo-SecureString -AsPlainText $b -Force
$d = Set-ADAccountPassword $a -Reset -NewPassword $c
}