Skip to content

Instantly share code, notes, and snippets.

View MattHodge's full-sized avatar

Matthew Hodgkins MattHodge

View GitHub Profile
# Start the Jenkins Server
Start-Service -Name Jenkins
# Get a list of trusted hosts
Get-Item WSMan:\localhost\Client\TrustedHosts
# Note that these commands don't create a list of trusted hosts, it simply replaces the trusted host with what you set via the command. If you need to add multiple hosts, they need to be comma seperated
# Trust all computers in a domain
Set-Item WSMan:\localhost\Client\TrustedHosts *.contoso.com
# Turst a single machine
Set-Item WSMan:\localhost\Client\TrustedHosts -Value myserver
# Ensure the build fails if there is a problem.
# The build will fail if there are any errors on the remote machine too!
$ErrorActionPreference = 'Stop'
# Create a PSCredential Object using the "User" and "Password" parameters that you passed to the job
$SecurePassword = $env:Password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $env:User, $SecurePassword
# Invoke a command on the remote machine.
# It depends on the type of job you are executing on the remote machine as to if you want to use "-ErrorAction Stop" on your Invoke-Command.
# Ensure the build fails if there is a problem.
# The build will fail if there are any errors on the remote machine too!
$ErrorActionPreference = 'Stop'
# Create a password variable using the stored password from the Jenkins Global Passwords
$SecurePassword = $env:PasswordForHodge | ConvertTo-SecureString -AsPlainText -Force
# If remoting to a machine with domain credentials, use "DOMAIN\YourUserName"
# If remoting to a machine on a workgroup, use "\YourUserName"
$User = "\Hodge"
@MattHodge
MattHodge / (CLIENT SIDE) check-service.ps1
Last active August 29, 2015 14:22
Sensu Windows Check
Param
(
# Param1 help description
[Parameter(Mandatory=$true)]
$ServiceName
)
$status = (Get-Service -name $ServiceName)
if ($status.Status -ne 'Running')
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Makes PowerShell pull you up about everything..
Set-StrictMode -Version Latest
# YOu don't need to put this in usually, but just to make sure in your ise.
$ErrorActionPreference = "Continue"
#Dot Source required Function Libraries
#. "Logging_Functions.ps1"
#----------------------------------------------------------[Declarations]----------------------------------------------------------
@MattHodge
MattHodge / vagrant_powershell_provision.rb
Created June 17, 2015 01:20
Vagrant PowerShell Provision
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "mwrock/Windows2012R2"
config.vm.guest = :windows
config.vm.communicator = "winrm"
@MattHodge
MattHodge / escapinghtml.ps1
Last active August 29, 2015 14:26
Escaping PowerShell
$title = "This is Matt's Page"
$price = 20
$color = 'red'
$html =
"
<HTML>
<HEAD>
<TITLE>$($title)</TITLE>
<BODY>
<font color=""$($color)"">
@MattHodge
MattHodge / 01_Blog_PSStringFormating_BasicExample.ps1
Created August 16, 2015 11:51
Description for 01_Blog_PSStringFormating_BasicExample.ps1
# A Basic String
$myString = 'The price of a Beer is $6.00'
Write-Output $myString
# Using String concatination
$myItem = 'Beer'
$myString = 'The price of a ' + $myItem + ' is $6.00'
Write-Output $myString
# Using the format operator
@MattHodge
MattHodge / 02_Blog_PSStringFormating_EscapingDollarSign.ps1
Created August 16, 2015 11:51
Description for 02_Blog_PSStringFormating_EscapingDollarSign.ps1
# Escaping the dollar sign using a back-tick
$myItem = 'Beer'
$myString = "The price of a $myItem is `$6.00"
Write-Output $myString