Skip to content

Instantly share code, notes, and snippets.

View rayterrill's full-sized avatar

Ray Terrill rayterrill

View GitHub Profile
#requires the winrm gem - sudo gem install -r winrm
require 'winrm'
endpoint = 'http://SERVER_FQDN:5985/wsman'
winrm = WinRM::WinRMWebService.new(endpoint, :negotiate, :user => 'USERNAME', :pass => 'PASSWORD')
winrm.create_executor do |executor|
executor.run_powershell_script("Get-Service | Where-Object {$_.Name -Like '*SQL*'}") do |stdout, stderr|
#executor.run_cmd("ipconfig /all") do |stdout, stderr| #use this if you'd rather run a command prompt
STDOUT.print stdout
#This builds out the base configuration for an IOT Thing + Certificate and Policy
$thingType = New-IOTThingType -ThingTypeName AdafruitWICEDFeather
$thing = New-IOTThing -ThingName WICEDFeatherA -ThingTypeName AdafruitWICEDFeather
$keysAndCert = New-IOTKeysAndCertificate
Update-IOTCertificate -CertificateId $keysAndCert.CertificateId -NewStatus Active
$policyDoc = @"
{
@rayterrill
rayterrill / ec2UserData.ps1
Created September 13, 2016 01:25
Bootstrap EC2 Instance with Chef Client using User Data
<powershell>
$region = 'us-west-2'
#grab our bootstrap files from s3
Read-S3Object -BucketName mybucket -Key client.rb -File c:\chef\client.rb -Region $region
Read-S3Object -BucketName mybucket -Key first-boot.json -File c:\chef\first-boot.json -Region $region
Read-S3Object -BucketName mybucket -Key validation.pem -File c:\chef\validation.pem -Region $region
Read-S3Object -BucketName mybucket -Key wget.ps1 -File c:\chef\wget.ps1 -Region $region
Read-S3Object -BucketName mybucket -Key MY_CERTIFICATE.crt -File c:\chef\trusted_certs\MY_CERTIFICATE.crt -Region $region
@rayterrill
rayterrill / advanceWindowsVMSnapshots.ps1
Created September 21, 2016 21:43
Advance Windows Domain Machine Snapshots to Avoid Machine Account Expiration Issues when Reverting to Snapshot
& "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
<#
We have several VMs we use for repetitive testing activities, and frequently need to revert them to a "known good"
snapshot in order to undo changes. If we forget to do this in the default 30 day machine account expiration window,
however, we need to work with our SYSADMIN team to join these back to the domain post-revert.
This script reverts machines to known good snapshots using the Name property of the snapshots. Not the most elegant
thing in the world (I'd love to see if others have better/slicker ideas!), but it should work for us.
#>
@rayterrill
rayterrill / GetLocalChocolateyPackages.ps1
Created September 29, 2016 18:35
Get Local Chocolatey Packages
#I can never remember this - Stashing this in Gist so I can find it. :D
chocolatey list -localonly
@rayterrill
rayterrill / configureVagrant.ps1
Last active December 13, 2016 18:13
Configure Vagrant Machine
$ProgressPreference='SilentlyContinue'
#Enable Remote DesktopSet-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
Set-NetFirewallRule -Name RemoteDesktop-UserMode-In-TCP -Enabled True
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name "UserAuthentication" -Value 1
#disable complex passwords
secedit /export /cfg c:\secpol.cfg
(gc C:\secpol.cfg).replace("PasswordComplexity = 1", "PasswordComplexity = 0") | Out-File C:\secpol.cfg
secedit /configure /db c:\windows\security\local.sdb /cfg c:\secpol.cfg /areas SECURITYPOLICY

Keybase proof

I hereby claim:

  • I am rayterrill on github.
  • I am rayterrill (https://keybase.io/rayterrill) on keybase.
  • I have a public key whose fingerprint is 6C65 D01E DC30 BDB6 0534 6990 7179 0937 DA2F AE8A

To claim this, I am signing this object:

#install USBtoUARTBridge to map the serial device to usb from www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx
#install this version of prolific console cable driver: http://www.adafruit.com/datasheets/PL2303%201.0.13.zip
#attach ESP8266 device via usb
#clear device MBP
/Library/Python/2.7/site-packages/esptool.py --port /dev/tty.SLAB_USBtoUART erase_flash
#clear device Surface
cd c:\wip\esptool
python .\esptool.py --port COM5 erase_flash
#requires that you have the .NET selenium webdriver installed http://selenium-release.storage.googleapis.com/3.0/selenium-dotnet-3.0.0.zip
#as well as the Chrome driver: https://sites.google.com/a/chromium.org/chromedriver/
#installed both of mine into C:\wip\selenium\net35
Set-Location C:\wip\selenium\net35
# Import the Selenium DLLs
Add-Type -Path "C:\wip\selenium\net35\Selenium.WebDriverBackedSelenium.dll"
Add-Type -Path "C:\wip\selenium\net35\ThoughtWorks.Selenium.Core.dll"
Add-Type -Path "C:\wip\selenium\net35\WebDriver.dll"
PS C:\wip\vagrant> vagrant powershell --debug
INFO global: Vagrant version: 1.9.1
INFO global: Ruby version: 2.2.5
INFO global: RubyGems version: 2.4.5.1
INFO global: VAGRANT_EXECUTABLE="C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.9.1\\bin\\vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="C:\\HashiCorp\\Vagrant\\embedded"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_OLD_ENV_="::=::\\"