Skip to content

Instantly share code, notes, and snippets.

royashbrook / genDimDate.cs
Created Jun 30, 2014
Generate Dimension Table in C#
View genDimDate.cs
//uses LINQPad
void Main()
List<dimDate> dimDates = genDimDate(
, DateTime.Parse("12/31/2017")
royashbrook / IterateOverWordFields.cs
Created Jun 30, 2014
iterate over word fields and formfields in LINQPad
View IterateOverWordFields.cs
void Main()
string sPath = @"c:\temp\somedoc.docx";
//using Microsoft.Office.Interop.Word
void ShowFields(string sPath)
//references for the com objects
Application oApp = null;
# 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
View securestring.ps1
#plaintext password
$pt= "P@ssword1"
#convert to secure string object
$oss= $pt | ConvertTo-SecureString -AsPlainText -Force
#secure string object as a string, this is what you store in a file
$sss= $oss| ConvertFrom-SecureString
View ListLocalAccounts.ps1
#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
View OneLiners.ps1
#Import CSV, dynamically generate column names
Import-Csv -Header (00..( (gc file.csv)[0].split(",").Count-1 )|%{"c{0}" -f $_}) -Path file.csv
View Send-Mail.ps1
## Send me an email
Send-MailMessage `
-From "name <>" `
-To @("me <>") `
-Attachments $fi.FullName `
-SmtpServer "" `
-Port 25 `
-Subject "Subject" `
-Body "PFA File: $($fi.Name)"
View Inventory-Machines.ps1
##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}
View Find-AD-User.ps1
# 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 ''}
Get-ADUser -Filter {surname -eq "ashbrook"} | measure
View Set-AD-Pass.ps1
#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
You can’t perform that action at this time.